Re: NSURLConnection and HTTP Headers
Re: NSURLConnection and HTTP Headers
- Subject: Re: NSURLConnection and HTTP Headers
- From: John Pannell <email@hidden>
- Date: Sun, 14 Jan 2007 19:30:39 -0700
Hi Drarok-
You want to look at the *response* object, not the request object.
In your code, you pass a reference to urlResponse to the
sendSynchronousRequest: method... assuming you set that variable up
earlier in code, you'll want to look at this object after your data
comes back from the server.
When looking for methods to interrogate the response, be sure to read
the documentation on NSHTTPURLResponse - the allHeaderFields method
returns a dictionary that you can look at.
Hope this helps!
John
John Pannell
Positive Spin Media
http://www.positivespinmedia.com
On Jan 14, 2007, at 6:17 PM, Drarok Ithaqua wrote:
Hi list, hope this mail finds you all well.
I've been trying to debug some PHP code I've been working on that
returns custom HTTP headers, so I thought it would be nice to have
a tool to show the headers that are returned from various queries,
rather than using telnet to port 80. Possibly reinventing the
wheel, but I need the cocoa practise.
I've got a semi-working app insofar as it sends a request to the
server, and shows me the response, but I don't seem to be able to
access the returned headers.
I'm doing something like the following:
<code>
NSMutableURLRequest *urlRequest = [[NSMutableURLRequest alloc]
initWithURL:[NSURL URLWithString:[urlField stringValue]]];
// Setting various options and custom request headers here...
NSData *urlData = [NSURLConnection
sendSynchronousRequest:urlRequest returningResponse:&urlResponse
error:&urlError];
NSString *resultString = [NSString stringWithCString:[urlData
bytes] length:[urlData length]];
NSRunAlertPanel(@"Results", @"Results:\r\n%@\r\nLength:%d", @"OK",
nil, nil, resultString, [urlData length]);
</code>
I have tried accessing [urlRequest allHTTPHeaderFields], but that
returns the request headers.
I expected that urlResponse would have something useful in, but
looking at the docs for that class, it doesn't really DO anything?
Am I barking up the wrong tree with these classes? Would it be
better to roll my own code directly on top of sockets, or subclass
NSURLRequest in some way?
I'm just after some guidance, here.
Thanks in advance for any suggestions.
- Drarok
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
40positivespinmedia.com
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden