所以我是 Obj-C 的新手,我正在尝试调用 Web 服务并接收它的响应...
在 Apple 文档中实现 NSURLConnection 的示例后,我将结果输出到 NSLog。看看这个:
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.
可以看到,数据为<>
接收到的数据输出为<3c3f786d 6c207665 7273696f 6e3d2231 2e30223f 3e3c7265 73706f6e 73653e3c 72657375 6c743e73 75636365 73733c2f 72657375 6c743e3c 2f726573 706f6e73 653e>
我的 PHP 服务只是回显一些 XML:
echo '<?xml version="1.0"?><response><result>success</result></response>';
有人可以给我线索吗?
最佳答案
响应格式采用 NSData
格式,如果我错了,有人可以纠正我,但这就是使用 NSLog
打印时显示的内容。您可以将其转换为 NSString
像这样,看看它是否有帮助:
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
关于Objective-C:NSURLConnection 响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5840612/