Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

The following code

fRequestHandle = HttpOpenRequestA(
                   fConnectHandle, 
                   "POST", url.c_str(), 
                   NULL, NULL, NULL,
                   INTERNET_FLAG_RELOAD|INTERNET_FLAG_NO_CACHE_WRITE, 
                   0); 

is returning NULL with GetLastError() returning 122. A search suggests this error is

122 (ERROR_INSUFFICIENT_BUFFER) The data area passed to a system call is too small. 

but gives no indication what buffer might be too small.

Which buffer might this relate to, and how can I make it bigger?

Update:

As has been pointed out, and detailed at http://support.microsoft.com/kb/208427, Internet Explorer, and presumably the wininet library, has a url limit of 2083 characters.

However looking at my url I find the url itself is around 40 characters. The 650k of data is in a name/value pair, for which wininet has no limit

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
786 views
Welcome To Ask or Share your Answers For Others

1 Answer

In general, your url should be 2k or less in size. Since you are performing a POST, you are heading in the right direction, its just that for the bulk of your data, you want to pass that as the body of the HTTP request like in this example:

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!

Cribbed from here: http://developers.sun.com/mobility/midp/ttips/HTTPPost/

Here's what I was thinking you would want to do:

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.
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...