以下代码
fRequestHandle = HttpOpenRequestA(
fConnectHandle,
"POST", url.c_str(),
NULL, NULL, NULL,
INTERNET_FLAG_RELOAD|INTERNET_FLAG_NO_CACHE_WRITE,
0);
返回 NULL,GetLastError() 返回 122。搜索表明此错误是
122 (ERROR_INSUFFICIENT_BUFFER) The data area passed to a system call is too small.
但没有指出哪个缓冲区可能太小。
这可能与哪个缓冲区相关,如何使其更大?
更新:
正如已指出的那样,详细信息参见 http://support.microsoft.com/kb/208427 、Internet Explorer,大概还有 wininet 库,URL 限制为 2083 个字符。
但是查看我的网址,我发现网址本身大约有 40 个字符。 650k 数据位于名称/值对中,wininet 对此没有限制
最佳答案
一般来说,您的网址大小应为 2k 或更小。由于您正在执行 POST,因此您正朝着正确的方向前进,只是对于大部分数据,您希望将其作为 HTTP 请求的正文传递,如下例所示:
POST /login.jsp HTTP/1.1
Host: www.mysite.com
User-Agent: Mozilla/4.0
Content-Length: 27
Content-Type: application/x-www-form-urlencoded
userid=joe&password=guessme <--You need to do this!
从这里抄袭:http://developers.sun.com/mobility/midp/ttips/HTTPPost/
这就是我认为你想做的事情:
std::string url("http://host.com/url");
std::string dataPayload("name=value&othername=anothervalue");//Query string payload style.
DWORD dataPayloadLength = dataPayload.length();
std::ostringstream headerStream;
headerStream << "content-length: ";
headerStream << dataPayloadLength;
std::string headers = headerStream.str();
DWORD headerLength = headers.length();
HINTERNET handle = HttpOpenRequest(hConnect,
"POST",
url.c_str(),
NULL, NULL, NULL,
INTERNET_FLAG_RELOAD|INTERNET_FLAG_NO_CACHE_WRITE,
0);
if(!handle) {
DWORD errorCode = GetLastError();
//Handle error here.
}
//Use this thing to send POST values.
if(! HttpSendRequest(handle,
headers.c_str(),
headerLength,
dataPayload, //lpOptional <--Your POST data...not really optional for you.
dataPayloadLength) {
DWORD errorCode = GetLastError();
//Handle error here.
}
关于c++ - 为什么 HttpOpenRequest 可能会失败并出现错误 122?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3362983/