NSString *message = [[NSString alloc] initWithFormat:@"<?xml version=\"1.0\" ?>\n<url><loc>http://www.abc.co.uk/index.php</loc><lastmod>2014-02-08</lastmod><changefreq>Monthly</changefreq><priority>0.9</priority></url>"];
NSString *url = [NSURL URLWithString:@"http://www.mypath.co.uk/ifo.xml"];
NSMutableURLRequest *Request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]];
[Request setHTTPMethod:@"POST"];
[Request setValue:@"application/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[Request setHTTPBody:[message dataUsingEncoding:NSUTF8StringEncoding]];
NSError *Error = nil;
NSLog(@"%@Post message", message);
Status.text = message;
_Connection = [[NSURLConnection alloc] initWithRequest:Request delegate:self];
if(_Connection)
{
NSLog(@"Connection Build");
}
else
{
NSLog(@"Connection error...");
NSLog(@"%@",Error);
}
任何使用它的人请在这里找出问题。
点击按钮时调用请求方法。
提前致谢。
NSLog
: 显示错误
NSURL length]: unrecognized selector sent to instance 0x89dac30
2014-02-14 15:55:26.513 eAgent[2369:a0b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSURL length]: unrecognized selector sent to instance 0x89dac30'
最佳答案
问题是:
NSString *url = [NSURL URLWithString:@"http://www.mypath.co.uk/ifo.xml"];
NSMutableURLRequest *Request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]];
URLWithString
是一个 NSURL
类方法,它返回一个 NSURL
而不是 NSString
。更改它并在请求中使用生成的 NSURL
对象,错误将消失。
像这样:
NSURL *url = [NSURL URLWithString:@"http://www.mypath.co.uk/ifo.xml"];
NSMutableURLRequest *Request = [NSMutableURLRequest requestWithURL:url];
关于php - 如何将带有xml的url请求发送到php页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21777645/