FW: http post ???
FW: http post ???
- Subject: FW: http post ???
- From: Mark Thomas <email@hidden>
- Date: Fri, 15 Oct 2004 17:51:48 +0100
- Organization: Coderus Ltd
Looking at the packets being sent it looks like there is a :80 after
server's address in 10.2 which 10.3 doesn't have, which I'm wondering if
that the problem, but there doesn't seem to a way to switch it off, well so
far.
Thanks
Mark.
---------------------------------------------------
I was wondering anybody on this might know why 10.3 works and 10.2.8
doesn't.
Thanks
Mark.
------ Forwarded Message
From: Mark Thomas <email@hidden>
Organization: Coderus Ltd
Reply-To: email@hidden
Date: Fri, 15 Oct 2004 15:40:37 +0100
To: Richard Rothwell <email@hidden>,
<email@hidden>
Subject: Re: http post ???
Thanks that cleared it up and worked great on 10.3.5, as I'm using just
kURLHTTPRequestBody ("username=mark&password=pass") and setting
kURLHTTPRequestMethod to "POST", but in 10.2.8 the same code didn't work
:-(.
Any ideas why ???.
Thanks
Mark.
>> I'm wondering what the best way to do a HTTP post, as I have in the
>> past
>> used the URL Access API calls, but there doesn't seen to be Post,
>> there's an
>> upload.
>>
> To do POST (from memory) you have to set the method,
> construct the body and then set the body.
>
> However the whole thing is a bugfest and the bugs change from version
> to version. You need to check that the headers are being constructed
> properly by looking at what goes out on the wire.
>
> For example in going from Jaguar to Panther the code changed so that
> now it is necessary to use colon/space instead of colon when separating
> the name/value pairs in the HTTP header. Otherwise it lops the first
> character
> of the value string.
>
> A synchronous POST is OK but doing the asynchronous stuff is the pits.
>
> /*
> ---------------------------------------------------------------------
> */
> OSStatus
> PerformHTTPPost(
> const char* inURL,
> char* inURLEncodedQuery,
> Size inQueryLength,
> int* outHttpStatusCode,
> char* outHttpStatusMessage,
> Size inMaxHttpStatusMessage,
> char* outHttpResponseBody,
> Size inMaxResponseBody)
> {
> OSStatus status = noErr;
>
> // Step over the leading "\r\n"
> // that was put there the keep the
> // screwy Windows code happy.
> inURLEncodedQuery += 2;
> inQueryLength -= 2;
>
> // Specify the URL in a urlReference
> URLReference urlReference;
> status = URLNewReference(
> inURL,
> &urlReference);
> if(status != noErr)
> {
> return status;
> }
> char userAgent[] = "Mozilla/4.03 [en] (Win95; I)"; // c-string
> Size userAgentLength = sizeof(userAgent);
> status = URLSetProperty(
> urlReference,
> kURLHTTPUserAgent,
> userAgent,
> userAgentLength);
> if(status != noErr)
> {
> return status;
> }
> // Load the urlReference with the POST data
> // Specify the request method
> char postMethod[] = "POST";
> Size methodLength = sizeof(postMethod);
> status = URLSetProperty(
> urlReference,
> kURLHTTPRequestMethod,
> postMethod,
> methodLength);
> if(status != noErr)
> {
> return status;
> }
> char contentType[] = "Content-Type:
> application/x-www-form-urlencoded"; // c-string
> Size contentTypeLength = sizeof(contentType);
> status = URLSetProperty(
> urlReference,
> kURLHTTPRequestHeader,
> contentType,
> contentTypeLength);
> if(status != noErr)
> {
> return status;
> }
> // Specify the request body.
> status = URLSetProperty(
> urlReference,
> kURLHTTPRequestBody,
> inURLEncodedQuery,
> inQueryLength);
> if(status != noErr)
> {
> throw status;
> }
> // Download remote data into into memory, not a file.
> FSSpec * destination = NULL;
> Handle destinationHandle = NewHandle(0);
> //URLOpenFlags openFlags = kURLDisplayProgressFlag;
> URLOpenFlags openFlags = 0;
> URLSystemEventUPP eventProc = NULL;
> void * userContext = NULL;
> status = URLDownload (
> urlReference,
> destination,
> destinationHandle,
> openFlags,
> eventProc,
> userContext);
> // Convert return download data to a c-string.
> UInt32 dataLength = GetHandleSize(destinationHandle);
> if(!(dataLength > 0))
> {
> return MemError();
> }
> SetHandleSize(destinationHandle, dataLength + 1);
> (*destinationHandle)[dataLength] = '\0';
> // Check for HTTP status error codes.
> // kURLHTTPRespHeader c-string.
> // kURLStatusString Pascal string
> char httpResponse[1024] = "";
> status = URLGetProperty(
> urlReference,
> kURLHTTPRespHeader,
> httpResponse,
> sizeof(httpResponse));
> if(status != noErr)
> {
> return status;
> }
> // Return HTTP response to caller.
> // First the status located on the first line of the response header
> char headerTemplate[] = "HTTP/1.1 %d %" MAX_REASON_PHRASE_BUFFER_STR
> "[^\r]\r\n";
> sscanf(
> httpResponse,
> headerTemplate,
> outHttpStatusCode,
> outHttpStatusMessage);
> // Return body of response
> strncpy(outHttpResponseBody, *destinationHandle, inMaxResponseBody);
> // Clean up
> DisposeHandle(destinationHandle);
> status = URLDisposeReference(urlReference);
> if(status != noErr)
> {
> return status;
> }
> return status;
> }
> /*
> ---------------------------------------------------------------------
> */
>
>
>
------ End of Forwarded Message
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden