Objective c 从url xcode获取数据
我试图从一个使用php的在线链接加载数据。该链接返回一个xml。 我想保存在iPad文档目录中的xml。 我正在尝试:Objective c 从url xcode获取数据,objective-c,ipad,download,Objective C,Ipad,Download,我试图从一个使用php的在线链接加载数据。该链接返回一个xml。 我想保存在iPad文档目录中的xml。 我正在尝试: NSString *post = @""; NSData *postData = [post dataUsingEncoding:NSISOLatin1StringEncoding allowLossyConversion:NO]; NSMutableURLRequest *urlRequest = [[[NSMutableURLRequest allo
NSString *post = @"";
NSData *postData = [post dataUsingEncoding:NSISOLatin1StringEncoding allowLossyConversion:NO];
NSMutableURLRequest *urlRequest = [[[NSMutableURLRequest alloc] init] autorelease];
[urlRequest setURL:[NSURL URLWithString:@"http://www.test.be/tools/xml_nieuwsbrief.php"]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setHTTPBody:postData];
NSData *urlData;
NSURLResponse *response;
NSError *error;
urlData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:&error];
if(!urlData) {
NSLog(@"No connection!");
}
NSLog(@"Receive:%d bytes",[urlData length]);
NSString *aStr = [[[NSString alloc] initWithData:urlData encoding:NSUTF8StringEncoding]autorelease];
NSLog(@"________%@", aStr);
字符串确实返回-null-,我一直在搜索internet,但没有找到任何可能导致我的问题的内容
有人能帮我让我知道我做错了什么吗
提前感谢,
Snowy我会检查响应对象的状态代码(将NSURLRRESPONSE对象更改为NSHTTPURLRRESPONSE,您将有一个STATUSSCODE属性可用)
如果您实际上从NSData响应中得到了-null-值,那么您可能应该查看服务器端脚本。可能它不需要一个空的POST请求?您是否检查了请求后的响应和错误对象?