WinHTTP richiesta GET C ++
-
22-09-2019 - |
Domanda
Prendo subito al punto.
-
Questo è ciò che una richiesta del browser appare come
GET /index.html HTTP / 1.1
-
Questo è ciò che fa winhttp
http://site.com/index.html HTTP / 1.1
C'è posso ottenere la richiesta WinHTTP per essere lo stesso formato di quella regolare? Sto usando VC ++ 2008 se fa alcuna differenza
Soluzione
Il codice dovrebbe essere simile a questa:
// Specify an HTTP server.
if (hSession)
hConnect = WinHttpConnect( hSession, L"www.example.com",
INTERNET_DEFAULT_HTTP_PORT, 0);
// Create an HTTP request handle.
if (hConnect)
hRequest = WinHttpOpenRequest( hConnect, L"GET", L"/path/resource.html",
NULL, WINHTTP_NO_REFERER,
WINHTTP_DEFAULT_ACCEPT_TYPES,
WINHTTP_FLAG_SECURE);
// Send a request.
if (hRequest)
bResults = WinHttpSendRequest( hRequest,
WINHTTP_NO_ADDITIONAL_HEADERS,
0, WINHTTP_NO_REQUEST_DATA, 0,
0, 0);
Puoi pubblicare queste tre chiamate dal proprio codice?
Si noti che l'URL completo è diviso in due parti - il nome host è specificato nella chiamata WinHttpConnect
, ma il percorso delle risorse relativo è specificato nella chiamata WinHttpOpenRequest
(come parametro pwszObjectName
). Sulla base della sua commento, a quanto pare si sta specificando l'URL completo nella chiamata WinHttpConnect
.