2017-02-18 191 views
0

我寫的應用程序爲UWP,這在服務器,我沒有得到在$ _ POST 數據請求服務器POST方法這是我的代碼示例UWP發送POST請求

public async void POSTreq() 
    { 
     Uri requestUri = new Uri("http://www.test.com"); 
     dynamic dynamicJson = new ExpandoObject(); 
     dynamicJson.username = "[email protected]".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] => [email protected]\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] 

回答

1

你的客戶端代碼行,所以問題很可能在你的服務器端。這是怎麼RequestBin看到您的要求:

FORM/POST參數

無頭

途經:1.1 vegur CF-雷:3330562272bd5b3f-HEL CF-參觀者: { 「計劃」:」內容長度:79 Cf-Ipcountry:FI連接: 關閉連接時間:0 X請求ID: e51d5210-7b13-497d-bb78-c7cbe54e2d41內容類型:application/json; 字符集= UTF-8總-路由的時間:0主機:requestb.in CF連接-IP: 91.155.129.79接受編碼:gzip RAW BODY

{ 「用戶名」:「[email protected]here你可以找到一提的是$ _ POST僅支持以下內容類型REGISTERUSER 「}

」, 」密碼「: 」123456789「, 」行動「」:

  • 應用程序/ x -www-form-urlencoded(簡單的 form-posts的標準內容類型)
  • 的multipart/form-data的編碼(主要用於文件 上傳)

你應該能夠讀取使用file_get_contents('php://input')的POST體。有關php://input的更多信息,請參閱PHP手冊。

+0

那麼我怎樣才能從uwp以php $ _POST可讀格式發送數據。我不想更改服務器端代碼 –