Win32 API 日本語リファレンス
ホームNetworking.WinInet › HttpSendRequestW

HttpSendRequestW

関数
指定したHTTPリクエストをサーバーへ送信する(Unicode版)。
DLLWININET.dll文字セットUnicode (-W)呼出規約winapiSetLastErrorあり対応OSWindows 2000 以降

シグネチャ

// WININET.dll  (Unicode / -W)
#include <windows.h>

BOOL HttpSendRequestW(
    void* hRequest,
    LPCWSTR lpszHeaders,   // optional
    DWORD dwHeadersLength,
    void* lpOptional,   // optional
    DWORD dwOptionalLength
);

パラメーター

名前方向
hRequestvoid*in
lpszHeadersLPCWSTRinoptional
dwHeadersLengthDWORDin
lpOptionalvoid*inoptional
dwOptionalLengthDWORDin

戻り値の型: BOOL

各言語での呼び出し定義

// WININET.dll  (Unicode / -W)
#include <windows.h>

BOOL HttpSendRequestW(
    void* hRequest,
    LPCWSTR lpszHeaders,   // optional
    DWORD dwHeadersLength,
    void* lpOptional,   // optional
    DWORD dwOptionalLength
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("WININET.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool HttpSendRequestW(
    IntPtr hRequest,   // void*
    [MarshalAs(UnmanagedType.LPWStr)] string lpszHeaders,   // LPCWSTR optional
    uint dwHeadersLength,   // DWORD
    IntPtr lpOptional,   // void* optional
    uint dwOptionalLength   // DWORD
);
<DllImport("WININET.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function HttpSendRequestW(
    hRequest As IntPtr,   ' void*
    <MarshalAs(UnmanagedType.LPWStr)> lpszHeaders As String,   ' LPCWSTR optional
    dwHeadersLength As UInteger,   ' DWORD
    lpOptional As IntPtr,   ' void* optional
    dwOptionalLength As UInteger   ' DWORD
) As Boolean
End Function
' hRequest : void*
' lpszHeaders : LPCWSTR optional
' dwHeadersLength : DWORD
' lpOptional : void* optional
' dwOptionalLength : DWORD
Declare PtrSafe Function HttpSendRequestW Lib "wininet" ( _
    ByVal hRequest As LongPtr, _
    ByVal lpszHeaders As LongPtr, _
    ByVal dwHeadersLength As Long, _
    ByVal lpOptional As LongPtr, _
    ByVal dwOptionalLength As Long) As Long
' Unicode(W): 文字列は ByVal As LongPtr とし StrPtr(unicodeStr) を渡す
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

HttpSendRequestW = ctypes.windll.wininet.HttpSendRequestW
HttpSendRequestW.restype = wintypes.BOOL
HttpSendRequestW.argtypes = [
    ctypes.POINTER(None),  # hRequest : void*
    wintypes.LPCWSTR,  # lpszHeaders : LPCWSTR 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')
HttpSendRequestW = Fiddle::Function.new(
  lib['HttpSendRequestW'],
  [
    Fiddle::TYPE_VOIDP,  # hRequest : void*
    Fiddle::TYPE_VOIDP,  # lpszHeaders : LPCWSTR optional
    -Fiddle::TYPE_INT,  # dwHeadersLength : DWORD
    Fiddle::TYPE_VOIDP,  # lpOptional : void* optional
    -Fiddle::TYPE_INT,  # dwOptionalLength : DWORD
  ],
  Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"
#[link(name = "wininet")]
extern "system" {
    fn HttpSendRequestW(
        hRequest: *mut (),  // void*
        lpszHeaders: *const u16,  // LPCWSTR 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.Unicode, SetLastError = true)]
public static extern bool HttpSendRequestW(IntPtr hRequest, [MarshalAs(UnmanagedType.LPWStr)] string lpszHeaders, uint dwHeadersLength, IntPtr lpOptional, uint dwOptionalLength);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WININET_HttpSendRequestW' -Namespace Win32 -PassThru
# $api::HttpSendRequestW(hRequest, lpszHeaders, dwHeadersLength, lpOptional, dwOptionalLength)
#uselib "WININET.dll"
#func global HttpSendRequestW "HttpSendRequestW" wptr, wptr, wptr, wptr, wptr
; HttpSendRequestW hRequest, lpszHeaders, dwHeadersLength, lpOptional, dwOptionalLength   ; 戻り値は stat
; hRequest : void* -> "wptr"
; lpszHeaders : LPCWSTR optional -> "wptr"
; dwHeadersLength : DWORD -> "wptr"
; lpOptional : void* optional -> "wptr"
; dwOptionalLength : DWORD -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "WININET.dll"
#cfunc global HttpSendRequestW "HttpSendRequestW" sptr, wstr, int, sptr, int
; res = HttpSendRequestW(hRequest, lpszHeaders, dwHeadersLength, lpOptional, dwOptionalLength)
; hRequest : void* -> "sptr"
; lpszHeaders : LPCWSTR optional -> "wstr"
; dwHeadersLength : DWORD -> "int"
; lpOptional : void* optional -> "sptr"
; dwOptionalLength : DWORD -> "int"
; BOOL HttpSendRequestW(void* hRequest, LPCWSTR lpszHeaders, DWORD dwHeadersLength, void* lpOptional, DWORD dwOptionalLength)
#uselib "WININET.dll"
#cfunc global HttpSendRequestW "HttpSendRequestW" intptr, wstr, int, intptr, int
; res = HttpSendRequestW(hRequest, lpszHeaders, dwHeadersLength, lpOptional, dwOptionalLength)
; hRequest : void* -> "intptr"
; lpszHeaders : LPCWSTR optional -> "wstr"
; dwHeadersLength : DWORD -> "int"
; lpOptional : void* optional -> "intptr"
; dwOptionalLength : DWORD -> "int"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	wininet = windows.NewLazySystemDLL("WININET.dll")
	procHttpSendRequestW = wininet.NewProc("HttpSendRequestW")
)

// hRequest (void*), lpszHeaders (LPCWSTR optional), dwHeadersLength (DWORD), lpOptional (void* optional), dwOptionalLength (DWORD)
r1, _, err := procHttpSendRequestW.Call(
	uintptr(hRequest),
	uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpszHeaders))),
	uintptr(dwHeadersLength),
	uintptr(lpOptional),
	uintptr(dwOptionalLength),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function HttpSendRequestW(
  hRequest: Pointer;   // void*
  lpszHeaders: PWideChar;   // LPCWSTR optional
  dwHeadersLength: DWORD;   // DWORD
  lpOptional: Pointer;   // void* optional
  dwOptionalLength: DWORD   // DWORD
): BOOL; stdcall;
  external 'WININET.dll' name 'HttpSendRequestW';
result := DllCall("WININET\HttpSendRequestW"
    , "Ptr", hRequest   ; void*
    , "WStr", lpszHeaders   ; LPCWSTR optional
    , "UInt", dwHeadersLength   ; DWORD
    , "Ptr", lpOptional   ; void* optional
    , "UInt", dwOptionalLength   ; DWORD
    , "Int")   ; return: BOOL
●HttpSendRequestW(hRequest, lpszHeaders, dwHeadersLength, lpOptional, dwOptionalLength) = DLL("WININET.dll", "bool HttpSendRequestW(void*, char*, dword, void*, dword)")
# 呼び出し: HttpSendRequestW(hRequest, lpszHeaders, dwHeadersLength, lpOptional, dwOptionalLength)
# hRequest : void* -> "void*"
# lpszHeaders : LPCWSTR optional -> "char*"
# dwHeadersLength : DWORD -> "dword"
# lpOptional : void* optional -> "void*"
# dwOptionalLength : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。