【发布时间】:2012-02-09 17:55:08
【问题描述】:
以下是我在服务器中的目标 php 文件的开头部分。
$xmlFile = file_get_contents("php://input");
echo $xmlFile."<br>";
很遗憾,浏览器的该页面上没有打印任何内容。
以下是我iphone端编程的一部分
NSURL *url = [NSURL URLWithString:@"http://www.mywebsite.com/target.php"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/xml; charset=utf-8" forHTTPHeaderField:@"Content- Type"];
NSMutableData *xmlData = [NSMutableData data];
[xmlData appendData: [[NSString stringWithFormat: @"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"] dataUsingEncoding: NSUTF8StringEncoding]];
[xmlData appendData: [[NSString stringWithFormat: @"<Packet xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance iphone_schema.xsd\" xmlns=\"http://www.mywebsite.com/iphone.xsd\">"] dataUsingEncoding: NSUTF8StringEncoding]];
[xmlData appendData: [[NSString stringWithFormat: @"<info1>%@<info1>",self.uuid] dataUsingEncoding: NSUTF8StringEncoding]];
//....append xml data strings in the same way
[request setHTTPBody:xmlData];
NSURLConnection *connect = [NSURLConnection connectionWithRequest:request delegate:self];
if(connect != nil){
NSLog(@"valid request");
}
连接对象不是零。但我不确定应用程序是否已将请求 POST 消息发送到 php 页面。
我在那个 php 文件中写了一些代码来测试连接。似乎没有从 iphone 收到任何信息。那么发生了什么?我已经测试了几个小时!
希望可以有人帮帮我!谢谢!
【问题讨论】: