ホーム › Networking.WinInet › HttpAddRequestHeadersW
HttpAddRequestHeadersW
関数HTTPリクエストに要求ヘッダーを追加する(Unicode版)。
シグネチャ
// WININET.dll (Unicode / -W)
#include <windows.h>
BOOL HttpAddRequestHeadersW(
void* hRequest,
LPCWSTR lpszHeaders,
DWORD dwHeadersLength,
HTTP_ADDREQ_FLAG dwModifiers
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hRequest | void* | in | HttpOpenRequestで取得したHTTP要求ハンドル。 |
| lpszHeaders | LPCWSTR | in | 追加するヘッダー文字列(広域)。CRLF区切りで複数可。 |
| dwHeadersLength | DWORD | in | lpszHeadersの文字数。-1でNULL終端文字列として扱う。 |
| dwModifiers | HTTP_ADDREQ_FLAG | in | ヘッダー追加方法を制御するフラグ(HTTP_ADDREQ_FLAG_ADD等)。 |
戻り値の型: BOOL
各言語での呼び出し定義
// WININET.dll (Unicode / -W)
#include <windows.h>
BOOL HttpAddRequestHeadersW(
void* hRequest,
LPCWSTR lpszHeaders,
DWORD dwHeadersLength,
HTTP_ADDREQ_FLAG dwModifiers
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("WININET.dll", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true)]
static extern bool HttpAddRequestHeadersW(
IntPtr hRequest, // void*
[MarshalAs(UnmanagedType.LPWStr)] string lpszHeaders, // LPCWSTR
uint dwHeadersLength, // DWORD
uint dwModifiers // HTTP_ADDREQ_FLAG
);<DllImport("WININET.dll", CharSet:=CharSet.Unicode, SetLastError:=True, ExactSpelling:=True)>
Public Shared Function HttpAddRequestHeadersW(
hRequest As IntPtr, ' void*
<MarshalAs(UnmanagedType.LPWStr)> lpszHeaders As String, ' LPCWSTR
dwHeadersLength As UInteger, ' DWORD
dwModifiers As UInteger ' HTTP_ADDREQ_FLAG
) As Boolean
End Function' hRequest : void*
' lpszHeaders : LPCWSTR
' dwHeadersLength : DWORD
' dwModifiers : HTTP_ADDREQ_FLAG
Declare PtrSafe Function HttpAddRequestHeadersW Lib "wininet" ( _
ByVal hRequest As LongPtr, _
ByVal lpszHeaders As LongPtr, _
ByVal dwHeadersLength As Long, _
ByVal dwModifiers 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
HttpAddRequestHeadersW = ctypes.windll.wininet.HttpAddRequestHeadersW
HttpAddRequestHeadersW.restype = wintypes.BOOL
HttpAddRequestHeadersW.argtypes = [
ctypes.POINTER(None), # hRequest : void*
wintypes.LPCWSTR, # lpszHeaders : LPCWSTR
wintypes.DWORD, # dwHeadersLength : DWORD
wintypes.DWORD, # dwModifiers : HTTP_ADDREQ_FLAG
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('WININET.dll')
HttpAddRequestHeadersW = Fiddle::Function.new(
lib['HttpAddRequestHeadersW'],
[
Fiddle::TYPE_VOIDP, # hRequest : void*
Fiddle::TYPE_VOIDP, # lpszHeaders : LPCWSTR
-Fiddle::TYPE_INT, # dwHeadersLength : DWORD
-Fiddle::TYPE_INT, # dwModifiers : HTTP_ADDREQ_FLAG
],
Fiddle::TYPE_INT)
# Wide strings: pass str.encode("UTF-16LE") + "\x00\x00"#[link(name = "wininet")]
extern "system" {
fn HttpAddRequestHeadersW(
hRequest: *mut (), // void*
lpszHeaders: *const u16, // LPCWSTR
dwHeadersLength: u32, // DWORD
dwModifiers: u32 // HTTP_ADDREQ_FLAG
) -> 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 HttpAddRequestHeadersW(IntPtr hRequest, [MarshalAs(UnmanagedType.LPWStr)] string lpszHeaders, uint dwHeadersLength, uint dwModifiers);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WININET_HttpAddRequestHeadersW' -Namespace Win32 -PassThru
# $api::HttpAddRequestHeadersW(hRequest, lpszHeaders, dwHeadersLength, dwModifiers)#uselib "WININET.dll"
#func global HttpAddRequestHeadersW "HttpAddRequestHeadersW" wptr, wptr, wptr, wptr
; HttpAddRequestHeadersW hRequest, lpszHeaders, dwHeadersLength, dwModifiers ; 戻り値は stat
; hRequest : void* -> "wptr"
; lpszHeaders : LPCWSTR -> "wptr"
; dwHeadersLength : DWORD -> "wptr"
; dwModifiers : HTTP_ADDREQ_FLAG -> "wptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "WININET.dll"
#cfunc global HttpAddRequestHeadersW "HttpAddRequestHeadersW" sptr, wstr, int, int
; res = HttpAddRequestHeadersW(hRequest, lpszHeaders, dwHeadersLength, dwModifiers)
; hRequest : void* -> "sptr"
; lpszHeaders : LPCWSTR -> "wstr"
; dwHeadersLength : DWORD -> "int"
; dwModifiers : HTTP_ADDREQ_FLAG -> "int"; BOOL HttpAddRequestHeadersW(void* hRequest, LPCWSTR lpszHeaders, DWORD dwHeadersLength, HTTP_ADDREQ_FLAG dwModifiers)
#uselib "WININET.dll"
#cfunc global HttpAddRequestHeadersW "HttpAddRequestHeadersW" intptr, wstr, int, int
; res = HttpAddRequestHeadersW(hRequest, lpszHeaders, dwHeadersLength, dwModifiers)
; hRequest : void* -> "intptr"
; lpszHeaders : LPCWSTR -> "wstr"
; dwHeadersLength : DWORD -> "int"
; dwModifiers : HTTP_ADDREQ_FLAG -> "int"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
wininet = windows.NewLazySystemDLL("WININET.dll")
procHttpAddRequestHeadersW = wininet.NewProc("HttpAddRequestHeadersW")
)
// hRequest (void*), lpszHeaders (LPCWSTR), dwHeadersLength (DWORD), dwModifiers (HTTP_ADDREQ_FLAG)
r1, _, err := procHttpAddRequestHeadersW.Call(
uintptr(hRequest),
uintptr(unsafe.Pointer(windows.StringToUTF16Ptr(lpszHeaders))),
uintptr(dwHeadersLength),
uintptr(dwModifiers),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction HttpAddRequestHeadersW(
hRequest: Pointer; // void*
lpszHeaders: PWideChar; // LPCWSTR
dwHeadersLength: DWORD; // DWORD
dwModifiers: DWORD // HTTP_ADDREQ_FLAG
): BOOL; stdcall;
external 'WININET.dll' name 'HttpAddRequestHeadersW';result := DllCall("WININET\HttpAddRequestHeadersW"
, "Ptr", hRequest ; void*
, "WStr", lpszHeaders ; LPCWSTR
, "UInt", dwHeadersLength ; DWORD
, "UInt", dwModifiers ; HTTP_ADDREQ_FLAG
, "Int") ; return: BOOL●HttpAddRequestHeadersW(hRequest, lpszHeaders, dwHeadersLength, dwModifiers) = DLL("WININET.dll", "bool HttpAddRequestHeadersW(void*, char*, dword, dword)")
# 呼び出し: HttpAddRequestHeadersW(hRequest, lpszHeaders, dwHeadersLength, dwModifiers)
# hRequest : void* -> "void*"
# lpszHeaders : LPCWSTR -> "char*"
# dwHeadersLength : DWORD -> "dword"
# dwModifiers : HTTP_ADDREQ_FLAG -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
# ※-W(Unicode)関数。なでしこ1はANSIのため -A 版の利用を推奨。