Ste*_*hen 1 iphone xcode http objective-c
我正在尝试从POST方法中检索数据,代码如下:
-(void)postXMLFeed:(NSString *)XMLStrPost
{
//NSLog (@"XML Feed3: ", XMLStrPost);
NSURL *url = [NSURL URLWithString:@"http://xxx.xxx.x.xxx/stephen/sync_upload.php"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setValue:@"text/xml" forHTTPHeaderField:@"Content-type"];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:[XMLStrPost dataUsingEncoding:NSASCIIStringEncoding]];
NSURLResponse *response;
NSError *error;
response = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
// Update log file.
NSLog(@"XML feed POSTED to website.");
//[super postXMLFeed];
}
Run Code Online (Sandbox Code Playgroud)
我的XML Feed存储在变量中XMLStrPost.上面的代码似乎有效,但我无法确认它.
脚本应该解压缩字符串并将其写入数据库,但这似乎不会发生.在解组之前,我想确认正在调用脚本.
如何确认sync_upload.php脚本被调用?
你误用了API. +[NSURLConnection sendSynchronousRequest:returningResponse:error]返回一个NSData对象,它是响应的主体.你将它分配给一个NSURLResponse对象,这意味着你不仅要破坏类型系统(你应该在编译时收到警告),但你也失去了指向NSURLResponse连接给你的指针.
这就像你用一颗子弹射击自己两次......("用一颗子弹射击两英尺"?)
| 归档时间: |
|
| 查看次数: |
244 次 |
| 最近记录: |