0
我已經寫了一些代碼,然後處理POST
請求。突然它停止工作,而我在API中沒有任何改變(它仍然可以和郵遞員一起工作),也沒有代碼。但是當我運行我的代碼時,我得到了一個405
錯誤(方法不允許)。 登錄方法:Webclient POST 405錯誤API
public byte[] logInViaAPI(string email, string password)
{
var response = APIHandler.Post("http://myurlhere", new NameValueCollection() {
{ "email", email },
{ "password", password },
});
return response;
}
這是我的POST方法:
public static byte[] Post(string uri, NameValueCollection pairs)
{
byte[] response = null;
try
{
using (WebClient client = new WebClient())
{
response = client.UploadValues(uri, pairs); //This is where I get my error
}
}
catch (WebException ex)
{
Console.Write(ex);
return null;
}
return response;
}
錯誤:
An unhandled exception of type 'System.Net.WebException' occurred in System.dll
其他信息:
The remote server returned an error: (405) Method Not Allowed.
我用HTTP request with post作爲一個來源(和其他一些主題),但我似乎無法弄清楚這個問題。
它開始失敗可能是由於服務器上的升級。確定問題的最佳方法是使用像wireshark或fiddler這樣的嗅探器。用郵差捕獲好的結果並比較你的應用程序不工作的http頭。讓你的http頭看起來像郵遞員頭。 – jdweng