winHTTP GET request C++

主宰稳场 提交于 2019-12-04 18:21:37

Your code should look like this:

// 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);

Can you post these three calls from your code?

Note that the full URL is split in two - the host name is specified in the WinHttpConnect call, but the relative resource path is specified in the WinHttpOpenRequest call (as the pwszObjectName parameter). Based on your comment, it seems you are specifying the full URL in the WinHttpConnect call.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!