ホーム › Networking.WinInet › HttpSendRequestA
HttpSendRequestA
関数指定したHTTPリクエストをサーバーへ送信する(ANSI版)。
シグネチャ
// WININET.dll (ANSI / -A)
#include <windows.h>
BOOL HttpSendRequestA(
void* hRequest,
LPCSTR lpszHeaders, // optional
DWORD dwHeadersLength,
void* lpOptional, // optional
DWORD dwOptionalLength
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| hRequest | void* | in |
| lpszHeaders | LPCSTR | inoptional |
| dwHeadersLength | DWORD | in |
| lpOptional | void* | inoptional |
| dwOptionalLength | DWORD | in |
戻り値の型: BOOL
各言語での呼び出し定義
// WININET.dll (ANSI / -A)
#include <windows.h>
BOOL HttpSendRequestA(
void* hRequest,
LPCSTR lpszHeaders, // optional
DWORD dwHeadersLength,
void* lpOptional, // optional
DWORD dwOptionalLength
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("WININET.dll", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
static extern bool HttpSendRequestA(
IntPtr hRequest, // void*
[MarshalAs(UnmanagedType.LPStr)] string lpszHeaders, // LPCSTR optional
uint dwHeadersLength, // DWORD
IntPtr lpOptional, // void* optional
uint dwOptionalLength // DWORD
);<DllImport("WININET.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function HttpSendRequestA(
hRequest As IntPtr, ' void*
<MarshalAs(UnmanagedType.LPStr)> lpszHeaders As String, ' LPCSTR optional
dwHeadersLength As UInteger, ' DWORD
lpOptional As IntPtr, ' void* optional
dwOptionalLength As UInteger ' DWORD
) As Boolean
End Function' hRequest : void*
' lpszHeaders : LPCSTR optional
' dwHeadersLength : DWORD
' lpOptional : void* optional
' dwOptionalLength : DWORD
Declare PtrSafe Function HttpSendRequestA Lib "wininet" ( _
ByVal hRequest As LongPtr, _
ByVal lpszHeaders As String, _
ByVal dwHeadersLength As Long, _
ByVal lpOptional As LongPtr, _
ByVal dwOptionalLength As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
HttpSendRequestA = ctypes.windll.wininet.HttpSendRequestA
HttpSendRequestA.restype = wintypes.BOOL
HttpSendRequestA.argtypes = [
ctypes.POINTER(None), # hRequest : void*
wintypes.LPCSTR, # lpszHeaders : LPCSTR optional
wintypes.DWORD, # dwHeadersLength : DWORD
ctypes.POINTER(None), # lpOptional : void* optional
wintypes.DWORD, # dwOptionalLength : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('WININET.dll')
HttpSendRequestA = Fiddle::Function.new(
lib['HttpSendRequestA'],
[
Fiddle::TYPE_VOIDP, # hRequest : void*
Fiddle::TYPE_VOIDP, # lpszHeaders : LPCSTR optional
-Fiddle::TYPE_INT, # dwHeadersLength : DWORD
Fiddle::TYPE_VOIDP, # lpOptional : void* optional
-Fiddle::TYPE_INT, # dwOptionalLength : DWORD
],
Fiddle::TYPE_INT)#[link(name = "wininet")]
extern "system" {
fn HttpSendRequestA(
hRequest: *mut (), // void*
lpszHeaders: *const u8, // LPCSTR optional
dwHeadersLength: u32, // DWORD
lpOptional: *mut (), // void* optional
dwOptionalLength: u32 // DWORD
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("WININET.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern bool HttpSendRequestA(IntPtr hRequest, [MarshalAs(UnmanagedType.LPStr)] string lpszHeaders, uint dwHeadersLength, IntPtr lpOptional, uint dwOptionalLength);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WININET_HttpSendRequestA' -Namespace Win32 -PassThru
# $api::HttpSendRequestA(hRequest, lpszHeaders, dwHeadersLength, lpOptional, dwOptionalLength)#uselib "WININET.dll"
#func global HttpSendRequestA "HttpSendRequestA" sptr, sptr, sptr, sptr, sptr
; HttpSendRequestA hRequest, lpszHeaders, dwHeadersLength, lpOptional, dwOptionalLength ; 戻り値は stat
; hRequest : void* -> "sptr"
; lpszHeaders : LPCSTR optional -> "sptr"
; dwHeadersLength : DWORD -> "sptr"
; lpOptional : void* optional -> "sptr"
; dwOptionalLength : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "WININET.dll"
#cfunc global HttpSendRequestA "HttpSendRequestA" sptr, str, int, sptr, int
; res = HttpSendRequestA(hRequest, lpszHeaders, dwHeadersLength, lpOptional, dwOptionalLength)
; hRequest : void* -> "sptr"
; lpszHeaders : LPCSTR optional -> "str"
; dwHeadersLength : DWORD -> "int"
; lpOptional : void* optional -> "sptr"
; dwOptionalLength : DWORD -> "int"; BOOL HttpSendRequestA(void* hRequest, LPCSTR lpszHeaders, DWORD dwHeadersLength, void* lpOptional, DWORD dwOptionalLength)
#uselib "WININET.dll"
#cfunc global HttpSendRequestA "HttpSendRequestA" intptr, str, int, intptr, int
; res = HttpSendRequestA(hRequest, lpszHeaders, dwHeadersLength, lpOptional, dwOptionalLength)
; hRequest : void* -> "intptr"
; lpszHeaders : LPCSTR optional -> "str"
; dwHeadersLength : DWORD -> "int"
; lpOptional : void* optional -> "intptr"
; dwOptionalLength : DWORD -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
wininet = windows.NewLazySystemDLL("WININET.dll")
procHttpSendRequestA = wininet.NewProc("HttpSendRequestA")
)
// hRequest (void*), lpszHeaders (LPCSTR optional), dwHeadersLength (DWORD), lpOptional (void* optional), dwOptionalLength (DWORD)
r1, _, err := procHttpSendRequestA.Call(
uintptr(hRequest),
uintptr(unsafe.Pointer(windows.BytePtrFromString(lpszHeaders))),
uintptr(dwHeadersLength),
uintptr(lpOptional),
uintptr(dwOptionalLength),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction HttpSendRequestA(
hRequest: Pointer; // void*
lpszHeaders: PAnsiChar; // LPCSTR optional
dwHeadersLength: DWORD; // DWORD
lpOptional: Pointer; // void* optional
dwOptionalLength: DWORD // DWORD
): BOOL; stdcall;
external 'WININET.dll' name 'HttpSendRequestA';result := DllCall("WININET\HttpSendRequestA"
, "Ptr", hRequest ; void*
, "AStr", lpszHeaders ; LPCSTR optional
, "UInt", dwHeadersLength ; DWORD
, "Ptr", lpOptional ; void* optional
, "UInt", dwOptionalLength ; DWORD
, "Int") ; return: BOOL●HttpSendRequestA(hRequest, lpszHeaders, dwHeadersLength, lpOptional, dwOptionalLength) = DLL("WININET.dll", "bool HttpSendRequestA(void*, char*, dword, void*, dword)")
# 呼び出し: HttpSendRequestA(hRequest, lpszHeaders, dwHeadersLength, lpOptional, dwOptionalLength)
# hRequest : void* -> "void*"
# lpszHeaders : LPCSTR optional -> "char*"
# dwHeadersLength : DWORD -> "dword"
# lpOptional : void* optional -> "void*"
# dwOptionalLength : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。