winHTTP GET请求C ++ [英] winHTTP GET request C++

查看:669
本文介绍了winHTTP GET请求C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我会明白的。



是否有任何可以让winHTTP请求与常规格式相同的格式?
我使用的是VC ++ 2008,如果它有任何区别的话。

解决方案

您的代码应该如下所示:

  //指定一个HTTP服务器。 
if(hSession)
hConnect = WinHttpConnect(hSession,Lwww.example.com,
INTERNET_DEFAULT_HTTP_PORT,0);

//创建一个HTTP请求句柄。
if(hConnect)
hRequest = WinHttpOpenRequest(hConnect,LGET,L/path/resource.html,
NULL,WINHTTP_NO_REFERER,
WINHTTP_DEFAULT_ACCEPT_TYPES,
WINHTTP_FLAG_SECURE);

//发送请求。
if(hRequest)
bResults = WinHttpSendRequest(hRequest,
WINHTTP_NO_ADDITIONAL_HEADERS,
0,WINHTTP_NO_REQUEST_DATA,0,
0,0);

你可以从你的代码中发布这三个调用吗?



请注意完整的URL分成两部分 - 主机名在 WinHttpConnect 调用中指定,但相对资源路径在 WinHttpOpenRequest 调用(作为 pwszObjectName 参数)。根据您的评论,您似乎在 WinHttpConnect 调用中指定了完整的网址。


I'll get right to the point.

  • This is what a browser request looks like

    GET /index.html HTTP/1.1

  • This is what winHTTP does

    GET http://site.com/index.html HTTP/1.1

Is there any I can get the winHTTP request to be the same format as the regular one? I'm using VC++ 2008 if it makes any difference

解决方案

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.

这篇关于winHTTP GET请求C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆