【问题标题】:Why might HttpOpenRequest fail with error 122?为什么 HttpOpenRequest 可能会失败并出现错误 122?
【发布时间】:2010-07-29 13:32:30
【问题描述】:

以下代码

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 没有限制

【问题讨论】:

  • 您发送的 URL 有多大?
  • URL 大约是 650k,但这是我们正在处理的数据类型

标签: c++ winapi httpwebrequest


【解决方案1】:

一般来说,您的网址大小应为 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.
}

【讨论】:

  • V 有趣,谢谢。我们将所有数据放入 HttpOpenRequest,并将空值传递给 HttpSendRequest。我会试试你的代码
【解决方案2】:

【讨论】:

  • WinINet 将 MAX_INTERNET_URL_LENGTH 定义为大约 2080 个字符;这是该链接中的人所达到的限制。
【解决方案3】:

经过一番挖掘,当 AV 或防火墙阻止了我的 GET 请求时,我收到了错误 122。

【讨论】:

    猜你喜欢
    • 2021-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-30
    • 2021-08-07
    • 1970-01-01
    相关资源
    最近更新 更多