繁体   English   中英

如何将带有xml的url请求发送到php页面

[英]how to send url request with xml to php page

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]];

URLWithStringNSURL类方法,它返回一个NSURL而不是NSString 更改它,并在请求中使用结果NSURL对象,错误将消失。

像这样:

NSURL *url = [NSURL URLWithString:@"http://www.mypath.co.uk/ifo.xml"];
NSMutableURLRequest *Request = [NSMutableURLRequest requestWithURL:url];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM