Re: URLAccess Stalls
Re: URLAccess Stalls
- Subject: Re: URLAccess Stalls
- From: email@hidden
- Date: Thu, 5 Jan 2006 16:20:36 -0700
On Jan 5, 2006, at 2:34 PM, email@hidden wrote:
Hi all, I finally bit the bullet and added code in my http wrapper
class to use CFNetwork, CFHTTPMessage and CFReadStream. It took
half a day of research to learn how it all works, and then half a
day to import the CoreFoundation and CoreServices bundles for the
constants and functions needed, since I am using CodeWarrior and
Carbon. It took another full day, noon to 2 am, to fill in all of
the OS X sections of my class. It's taken another day of testing
so far to get it working, but I am not quite there yet because I
have uncovered a bug in CFNetwork that I am not sure Apple is aware
of. So anyway, figure on at least 3 full days to convert your
URLAccess code to CFNetwork, which is not too bad I guess, and
CFNetwork is MUCH faster than URLAccess. BTW https is working
fine, it's all working quite well actually, except:
***CFNetwork either inserts an extra \r\n between the header and
body of a POST request, or is sending the header and body in 2
steps***
So I am at the end of the line because none of the forms on my site
work, and I dunno where to go from here unless someone can help me
solve this bug. Here are all of the gory details:
-------------------------------------------------------------
I build the request by calling these lines:
////////////////////
CFHTTPMessageRef messageRef
char requestBody = "user=test&pass=test";
CFDataRef dataRef;
messageRef = CFHTTPMessageCreateRequest( kCFAllocatorDefault, CFSTR
("POST"), CFSTR("http://mysite.com"), kCFHTTPVersion1_1 );
dataRef = CFDataCreateWithBytesNoCopy( nil, (unsigned char*)
requestBody , strlen( requestBody ), kCFAllocatorNull );
CFHTTPMessageSetHeaderFieldValue( messageRef, CFSTR( "Content-
Type" ), CFSTR( "application/x-www-form-urlencoded" ) );
CFHTTPMessageSetBody( messageRef, dataRef );
readStreamRef = CFReadStreamCreateForHTTPRequest
( kCFAllocatorDefault, messageRef );
CFReadStreamOpen( readStreamRef );
The CFHTTPMessageSetHeaderFieldValue() line is the answer, just
insert it and everything works, would you believe it? I found it in
this post from only a few weeks ago:
http://lists.apple.com/archives/macnetworkprog/2005/Dec/msg00069.html
You have to manually set the "Content-Type" header to "application/x-
www-form-urlencoded" if using POST. This is a pretty huge piece of
errata, and needs to be discussed in apple's documentation. At least
as far as CFNetwork doing it differently than URLAccess did, even if
it's not technically a bug.
On Jan 5, 2006, at 3:21 PM, Jim Luther wrote:
Zack,
I don't think this is a bug.
First, it looks like you are using tcpflow to look at the packets.
tcpflow throws an extra blank line into it's output between
packets. That's the extra "\r\n between the header and body of a
POST request" you are seeing.
Second, an HTTP message can be split into multiple tcp packets and
it will not make any difference to the contents of the data stream.
It's just slightly more overhead for short messages (messages that
would fit into one tcp packet) because the message is sent in two
packets instead of one.
Thanx for the heads up, that makes sense about multiple tcp packets
coming as one stream.
Well, hope this helps someone in the future,
------------------------------------------------------------------------
Zack Morris Z Sculpt Entertainment This Space
email@hidden http://www.zsculpt.com For Rent
------------------------------------------------------------------------
If the doors of perception were cleansed, everything would appear to man
as it is, infinite. -William Blake, The Marriage of Heaven and Hell
_______________________________________________
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