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

标签 php ios iphone objective-c post

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/

相关文章:

php - Laravel Forge 部署失败

php - 如何获取另一个页面上的 vbulletin 注销哈希值? (PHP)

ios - NSURLSession 子类化

php - 无法使用 HTACCESS 创建漂亮的 url

php - 输出中的重复记录

ios - 快速恢复 AVAudioPlayer 中的声音

iphone - 使用 ASIHTTPRequest 通过 NSDictionary 发布嵌套参数

iOS 10 iPhone 6S 使用触觉引擎播放触觉反馈或振动

iphone - UIViewController - 无法成为第一响应者

iphone - 如何在 iOS Gamecenter match.participants 中找到已满的座位?