簡體   English   中英

找不到帶有請求404的HTTP請求

[英]HTTP request with post 404 not found

我在帖子中使用了HTTP請求的最高答案,但是在Visual Studio中彈出錯誤消息,提示未找到404遠程服務器。

該網站存在,它是一個綁定到我路由器的IP地址的Rails應用程序。 在瀏覽器中使用以下url更新Rails應用程序中申請人實體的屬性。 但是,使用c#應用程序執行此操作無效。

http://<ADDRESS HERE>:3000/api/v1/applicants/update?id=2&door=true

我有ff:

using System.IO;
using System.Net;
using System.Text; 

我在btn點擊中使用了以下代碼

private void button1_Click (object sender, EventArgs e){
    var request = (HttpWebRequest)WebRequest.Create("http://<ADDRESS HERE>:3000/api/v1/applicants/update");

    var postData = "id=2";
        postData += "&door=true";
    var data = Encoding.ASCII.GetBytes(postData);

    request.Method = "POST";
    request.ContentType = "application/x-www-form-urlencoded";
    request.ContentLength = data.Length;

    using (var stream = request.GetRequestStream())
    {
        stream.Write(data, 0, data.Length);
    }

    var response = (HttpWebResponse)request.GetResponse();

    var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
}

您確定需要執行POST請求而不是GET請求嗎? 我問,因為您的問題似乎不一致。 首先,您說要進入網址

http://<ADDRESS HERE>:3000/api/v1/applicants/update?id=2&door=true

這是一個帶有querystring參數的url,但是在代碼中,您將querystring分開並將這些參數作為POST數據發送。

GET請求看起來像這樣

GET http://<ADDRESS HERE>:3000/api/v1/applicants/update?id=2&door=true HTTP/1.1
Host: <ADDRESS HERE>
... (more headers)

和POST請求:

POST http://<ADDRESS HERE>:3000/api/v1/applicants/update HTTP/1.1
Host: <ADDRESS HERE>
Content-type: application/x-www-form-urlencoded
... (more headers)

id=2&door=true

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM