2017-06-06 38 views
1

我試圖發佈以休息。httpClient.PostAsync返回「方法不允許」(在winform應用程序中運行)

這是我的代碼:

 string URL = "http://xxx.xxx.x.xx:8080/Name/NAME/"; 
    string urlParameters = "?key=T_PAPPS&value=sofsof"; 

    HttpClient client = new HttpClient(); 
    client.BaseAddress = new Uri(URL); 

    client.DefaultRequestHeaders.Accept.Add(
    new MediaTypeWithQualityHeaderValue("application/x-www-form-urlencoded")); 

    HttpResponseMessage response = client.PostAsync(URL, new StringContent(urlParameters)).Result; 

我的應用程序是WinForm應用程序(而不是web)。

我在做什麼錯?

感謝您的提前。

(restsharp返回同樣的錯誤(在那裏我也沒有成功更改爲應用程序/應用程序/ JSON)的X WWW的形式,進行了urlencoded)

+1

那麼可能它不接受POST請求。 –

回答

0

如果你使用的查詢字符串參數(即?鍵=值)你不需要發佈。嘗試更換您的最後一行:

HttpResponseMessage response = client.GetAsync(URL + urlParameters).Result; 

您可能還需要刪除最後一個「/」在你的URL字符串。

相關問題