views:

104

answers:

2

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

+1  A: 

EDIT:

Looks like this guy had the same problem, the URL is too long.

http://social.msdn.microsoft.com/Forums/en-US/windowsmobiledev/thread/68612c89-bbce-4d88-926d-5d76771be944

James
WinINet defines MAX_INTERNET_URL_LENGTH as roughly 2080 characters; this is the limit the guy in that link is hitting.
Luke
+1  A: 

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-type: ";
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.
}
ntcolonel
V interesting, thanks. We put all our data in the HttpOpenRequest, and pass nulls to HttpSendRequest. I will give your code a go
David Sykes