dcolumbus
dcolumbus

Reputation: 9714

Objective-C: NSURLConnection response?

So I'm new to Obj-C and I'm trying to call a web service and receive it's response...

After implementing the example in the Apple docs for NSURLConnection, I'm outputting my results to NSLog. Check this out:

2011-04-30 01:30:24.831 Cocoa_Sandbox[18424:903] The data was: <>
2011-04-30 01:30:25.837 Cocoa_Sandbox[18424:903] Got the response: <NSHTTPURLResponse: 0x100104110>
2011-04-30 01:30:25.838 Cocoa_Sandbox[18424:903] Receieved the data: <3c3f786d 6c207665 7273696f 6e3d2231 2e30223f 3e3c7265 73706f6e 73653e3c 72657375 6c743e73 75636365 73733c2f 72657375 6c743e3c 2f726573 706f6e73 653e>
2011-04-30 01:30:25.838 Cocoa_Sandbox[18424:903] Connection finished loading.

As you can see, the data is <> and the received data output is <3c3f786d 6c207665 7273696f 6e3d2231 2e30223f 3e3c7265 73706f6e 73653e3c 72657375 6c743e73 75636365 73733c2f 72657375 6c743e3c 2f726573 706f6e73 653e>

My PHP service is just echoing some XML:

echo '<?xml version="1.0"?><response><result>success</result></response>';

Can someone give me a clue?

Upvotes: 0

Views: 2432

Answers (2)

nielsbot
nielsbot

Reputation: 16031

BTW--I recommend looking into RestKit or ASIHTTP for this stuff... it can save you a lot of work. (ASIHTTP is basically a browser without the graphical front-end)

http://allseeing-i.com/ASIHTTPRequest/ http://restkit.org/

RestKit is newer and looks cool, but I haven't personally tried it. I've used ASIHTTPRequest quite a bit and it's very good.

Upvotes: 0

xoail
xoail

Reputation: 3074

The response format is in NSData, and someone can correct me if I am wrong, but that's what gets shown if printed with NSLog. You can convert it to an NSString like this and see if it helps:

NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];

Upvotes: 5

Related Questions