【问题标题】:$_POST remaining empty$_POST 为空
【发布时间】:2011-11-09 20:25:07
【问题描述】:

这个问题来自:Asynchronous POST to server。为了吸引具有正确知识的人(它与服务器而不是 Objective-C 代码有关),我创建了一个新问题。

我正在尝试从 Objective-C 中发布到服务器。然而,在服务器上调试时,我注意到 $_POST 变量仍然为空。我认为(真的不确定)这与其中一件事情有关:

  • 我不知道的重定向,它清空了 $_POST 变量
  • $_SERVER 的打印包含以下内容:[REQUEST_METHOD] => GET ???

我在代码中使用的原始网址是:http://eng.studev.groept.be/web2.0/a11_web02/testApp.php 打印 $_SERVER 变量会导致:

[HTTP_ACCEPT] => text/html, application/xhtml+xml, */* 
[HTTP_REFERER] => http://eng.studev.groept.be/web2.0/a11_web02/ 
[HTTP_ACCEPT_LANGUAGE] => nl-BE 
[HTTP_USER_AGENT] => Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0) 
[HTTP_UA_CPU] => AMD64 
[HTTP_ACCEPT_ENCODING] => gzip, deflate 
[HTTP_HOST] => eng.studev.groept.be 
[HTTP_CONNECTION] => Keep-Alive 
[PATH] => C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Dell\SysMgt\RAC4;C:\Program Files (x86)\Dell\SysMgt\oma\bin;C:\Program Files (x86)\Apache Software Foundation\Apache2.2\svn\bin;C:\Program Files (x86)\Apache Software Foundation\Apache2.2\php;C:\Program Files (x86)\Java\jre6\bin;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\;C:\Program Files (x86)\Microsoft SQL Server\100\DTS\Binn\ 
[SystemRoot] => C:\Windows 
[COMSPEC] => C:\Windows\system32\cmd.exe 
[PATHEXT] => .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC 
[WINDIR] => C:\Windows 
[SERVER_SIGNATURE] => [SERVER_SOFTWARE] => Apache/2.2.17 (Win32) DAV/2 mod_ssl/2.2.17 OpenSSL/0.9.8o SVN/1.6.13 PHP/5.3.3 
[SERVER_NAME] => eng.studev.groept.be 
[SERVER_ADDR] => 193.190.255.36 [SERVER_PORT] => 80 
[REMOTE_ADDR] => 193.190.253.160 
[DOCUMENT_ROOT] => D:/webroot/eng 
[SERVER_ADMIN] => //censored
[SCRIPT_FILENAME] => D:/webroot/eng/web2.0/a11_web02/testApp.php 
[REMOTE_PORT] => 49187 
[GATEWAY_INTERFACE] => CGI/1.1 
[SERVER_PROTOCOL] => HTTP/1.1 
[REQUEST_METHOD] => GET 
[QUERY_STRING] => [REQUEST_URI] => /web2.0/a11_web02/testApp.php 
[SCRIPT_NAME] => /web2.0/a11_web02/testApp.php 
[PHP_SELF] => /web2.0/a11_web02/testApp.php 
[REQUEST_TIME] => 1320869183

有没有人对此变得更聪明?

提前致谢

编辑

生成 POST 请求的代码:

NSString *post = [[NSString alloc] initWithFormat:@"email=%@&password=%@", self.email.text, self.password.text];    
NSData *postEncoded = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:NO];
NSString *postLength = [NSString stringWithFormat:@"%d", [postEncoded length]];

NSURL *url = [NSURL URLWithString:@"http://eng.studev.groept.be/web2.0/a11_web02/testApp.php"];

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postEncoded];

// asynchronous request
self.connection = [NSURLConnection connectionWithRequest:request delegate:self];

【问题讨论】:

  • 是的,这是一个 GET 请求,所以 $_POST 是空的。那又怎样?
  • 如果我的代码中有这一行,它怎么可能是 GET 请求:[request setHTTPMethod:@"POST"]; ?显然,出了点问题.. :)
  • 你能展示你当前设置 POST 请求的代码吗?
  • 使用代码编辑问题以设置 POST 请求。

标签: php post httprequest server-side


【解决方案1】:

[REQUEST_METHOD] => GET

你没有发布任何东西。

【讨论】:

  • 我的代码中有这一行:[request setHTTPMethod:@"POST"];我的 HTTPBody 包含 POST 变量..
  • @mmvie 你应该发布一个关于你正在编写的代码的新问题,然后找出它为什么没有发出正确的请求。
猜你喜欢
  • 1970-01-01
  • 2015-06-24
  • 2013-04-27
  • 2011-11-24
  • 2012-12-21
  • 2011-05-02
  • 2017-01-21
  • 2019-12-29
  • 1970-01-01
相关资源
最近更新 更多