我为UWP编写应用程序,它在服务器中使用POST方法请求服务器我没有在$ _POST中获取数据 这是我的代码示例
public async void POSTreq()
{
Uri requestUri = new Uri("http://www.test.com");
dynamic dynamicJson = new ExpandoObject();
dynamicJson.username = "example@gmail.com".ToString();
dynamicJson.password = "123456789";
dynamicJson.action = "REGISTERUSER";
string json = "";
json = Newtonsoft.Json.JsonConvert.SerializeObject(dynamicJson);
var objClint = new System.Net.Http.HttpClient();
System.Net.Http.HttpResponseMessage respon = await objClint.PostAsync(requestUri, new StringContent(json,System.Text.Encoding.UTF8,"application/json"));
}
在服务器端,我得到空POST
DEBUG: == post() [Array\n(\n)\n]
DEBUG: == get() [Array\n(\n)\n]
DEBUG: == server() [Array\n(\n [CONTENT_LENGTH] => 55\n [CONTENT_TYPE] => application/json; charset=utf-8\n [HTTP_HOST] => www.taskera.com\n [HTTP_CONNECTION] => Keep-Alive\n [PATH] => /sbin:/usr/sbin:/bin:/usr/bin\n [SERVER_SIGNATURE] => <address>Apache/2.2.15 (CentOS) Server at www.taskera.com Port 80</address>\n\n [SERVER_SOFTWARE] => Apache/2.2.15 (CentOS)\n [SERVER_NAME] => www.taskera.com\n [SERVER_ADDR] => 192.168.1.187\n [SERVER_PORT] => 80\n [REMOTE_ADDR] => 192.168.1.34\n [DOCUMENT_ROOT] => /var/www/html\n [SERVER_ADMIN] => root@localhost\n [SCRIPT_FILENAME] => /var/www/html/index.php\n [REMOTE_PORT] => 50574\n [GATEWAY_INTERFACE] => CGI/1.1\n [SERVER_PROTOCOL] => HTTP/1.1\n [REQUEST_METHOD] => POST\n [QUERY_STRING] => \n [REQUEST_URI] => /\n [SCRIPT_NAME] => /index.php\n [PHP_SELF] => /index.php\n [REQUEST_TIME] => 1487390506\n)\n]
答案 0 :(得分:1)
您的客户端代码没问题,因此很可能是您服务器端的问题。这就是RequestBin查看您的请求的方式:
FORM / POST PARAMETERS
无HEADERS
Via:1.1 vegur Cf-Ray:3330562272bd5b3f-HEL Cf-Visitor: {“scheme”:“http”}内容长度:79 Cf-Ipcountry:FI连接: 关闭连接时间:0 X-Request-Id: e51d5210-7b13-497d-bb78-c7cbe54e2d41 Content-Type:application / json; charset = utf-8 Total-Route-Time:0主机:requestb.in Cf-Connecting-Ip: 91.155.129.79接受编码:gzip RAW BODY
{ “用户名”: “example@gmail.com”, “密码”: “123456789”, “动作”: “REGISTERUSER”}
从here您可以看到$ _POST仅支持以下内容类型:
您应该能够使用file_get_contents('php://input')
阅读POST正文。有关php://input的更多信息,请参阅PHP手册。