$_POST 仍为空

发布于 2024-12-14 10:42:40 字数 3495 浏览 2 评论 0原文

这个问题是由于:异步 POST 到服务器。为了让人们了解正确的知识(它与服务器而不是 Objective-C 代码有关),我创建了一个新问题。

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

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

我在代码中使用的原始网址是: 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];

This question came as a result out of: Asynchronous POST to server. To reach people with the correct knowledge (it has to do with the server instead of the objective-C code) I created a new question.

I'm trying to POST to a server from within objective-C. When debugging on the server however, I noticed that the $_POST variable remains empty. I think (really not sure) it has to do with one of these things:

  • a redirect that I am not aware of, which empties the $_POST variable
  • print of $_SERVER contains this: [REQUEST_METHOD] => GET ???

The original url I am using in my code is: http://eng.studev.groept.be/web2.0/a11_web02/testApp.php
Printing the $_SERVER variable results in this:

[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

Anyone getting wiser out of this?

Thanks in advance

Edit

Code to generate the POST request:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

丑丑阿 2024-12-21 10:42:40

<代码>[REQUEST_METHOD] => GET

您没有发布任何内容。

[REQUEST_METHOD] => GET

You didn't post anything.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文