为什么$ _POST数组空PHP后用POST数据的请求数组、数据、_POST、POST

由网友(一个人的花花世界|▍)分享简介:我做一个POST请求的页面getremote.php用POST数据,但在$ _POST数组似乎是空的。将不胜感激,如果有人能告诉我,我做错了。I make a post request to the the page getremote.php with post data but the $_POST array...

我做一个POST请求的页面getremote.php用POST数据,但在$ _POST数组似乎是空的。将不胜感激,如果有人能告诉我,我做错了。

I make a post request to the the page getremote.php with post data but the $_POST array seems to be empty. Would be grateful if anyone can tell me what I've done wrong.

JavaScript的code,使请求

The javascript code to make the request is

var postdata = "Content-Type: application/x-www-form-urlencodednnedits=" + this.createEditXMLtext(this.editXMLstruct);
 var xmlhttp;
 if (window.XMLHttpRequest)
   {// code for IE7+, Firefox, Chrome, Opera, Safari
   xmlhttp=new XMLHttpRequest();
   }
 else
   {// code for IE6, IE5
   xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
   }
  dispmes("processing edits");
 xmlhttp.open("POST",userProfile.homeurl + "?remoteurl=" + userProfile.homeurl + "&cmdeditprofile&password=password",false);

 xmlhttp.send(postdata);

 var response = xmlhttp.responseXML;

在这里this.createEditXMLtext(this.editXMLstruct)只是简单地创建一个字符串

where this.createEditXMLtext(this.editXMLstruct) simply creates a string

我还没有收到这个问题,似乎并不具有相同的解决方案,因为谁也发布类似问题的其他人。 PHP的code在userProfile.homeurl +是

I haven't had this problem before and don't seem to have the same solution as other people who have posted similar problems. The php code at userProfile.homeurl + " is

header("Content-type: text/xml");
 $query = '';                  
    foreach( $_POST as $key => $value ){ 
  $query .= "$key=$value&";
 }
 echo do_post_request($_GET['remoteurl'] . $qstring,$query);

但字符串$查询总是空的 - 我通过添加回声$查询到文件底部

but the string $query is always empty - I checked it by adding echo $query to the bottom of the file

推荐答案

您传递给的发()应该是整个身体后,你已经包含在它的头。当该机构达到PHP,它将无法解析为EN codeD格式的数据。

The value you pass to send() should be the entire post body, and you've included a header in it. When that body reaches PHP, it will fail to parse it as encoded form data.

相反,通过调用 setRequestHeader设置的数据类型()

 //create the postdata, taking care over the encoding
 var postdata = "edits=" + encodeURI(this.createEditXMLtext(this.editXMLstruct));

 //let server know the encoding we used for the request body
 xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

 //and here we go 
 xmlhttp.send(postdata);
阅读全文

相关推荐

最新文章