我的iphone应用程序如何向服务器发送数据;什么是php文件?

我的iphone应用程序如何向服务器发送数据;什么是php文件?,php,iphone,http,post,Php,Iphone,Http,Post,以下是服务器中目标php文件的开始部分。 $xmlFile = file_get_contents("php://input"); echo $xmlFile."<br>"; $xmlFile=文件获取内容(“php://input"); echo$xmlFile.“”; 不幸的是,在浏览器中该页上没有打印任何内容 以下是我的iphone端编程的一部分 NSURL *url = [NSURL URLWithString:@"http://www.mywebsite.com/tar

以下是服务器中目标php文件的开始部分。

$xmlFile = file_get_contents("php://input");
echo $xmlFile."<br>";
$xmlFile=文件获取内容(“php://input");
echo$xmlFile.“
”;
不幸的是,在浏览器中该页上没有打印任何内容

以下是我的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");
}
NSURL*url=[NSURL URLWithString:@”http://www.mywebsite.com/target.php"];
NSMutableURLRequest*请求=[NSMutableUrlRequestRequestWithURL:url];
[请求设置HttpMethod:@“POST”];
[RequestSetValue:@“application/xml;charset=utf-8”用于HttpHeaderField:@“Content-Type”];
NSMutableData*xmlData=[NSMutableData];
[xmlData appendData:[[NSString stringWithFormat:@”“]dataUsingEncoding:NSUTF8StringEncoding]];
[xmlData appendData:[[NSString stringWithFormat:@”“]dataUsingEncoding:NSUTF8StringEncoding]];
[xmlData appendData:[[NSString stringWithFormat:@“%@”,self.uuid]dataUsingEncoding:NSUTF8StringEncoding];
//..以相同的方式附加xml数据字符串
[请求setHTTPBody:xmlData];
NSURLConnection*connect=[NSURLConnection connectionWithRequest:request委托:self];
如果(连接!=nil){
NSLog(@“有效请求”);
}
connect对象不是nil。但我不确定该应用程序是否已将requestpost消息发送到php页面

我在php文件中编写了一些代码来测试连接。似乎iphone没有收到任何信息。发生了什么事?我已经测试了好几个小时了
希望有人能帮助我!谢谢

设置您的。这将帮助您更好地诊断问题,并查看问题是在iPhone还是服务器端

另外,如果您发送POST请求。因此,您不需要读取PHP的输入流。使用


您还可以通过从命令行发送请求来确保PHP脚本是正确的。例如,
curl
on*nix

试试ngrep。这可能会有帮助

从尝试设置开始

然后做一个测试

brew install ngrep
然后

sudo ngrep host mywebsite.com port 80

这将显示在mywebsite.com上设备和服务器之间发送和接收的数据。

$xmlFile=file\u get\u contents(“php://input"); echo$xmlFile.“

这只会在您从发布到input的浏览器中查看时回显某些内容,而如果您的iOS发布到PHP,然后您在发布后访问PHP,则不会发生这种情况

一般来说,您根本无法通过这种方式验证它。您必须用PHP设计响应,并设置委托方法来处理PHP返回的任何内容

例如:

$xmlFile = file_get_contents("php://input");
if ($xmlFile) {
echo "{\"file\":\"$xmlFile\"}";
}
通过这种方式,您可以使用NSJSONSerializer在iOS中解码响应,并查看您发布的内容与返回的内容相同。 }