簡體   English   中英

RestSharp 返回 BadRequest 錯誤但 PostMan 工作正常

[英]RestSharp returns BadRequest error But PostMan works correctly

我有這段代碼可以將文件上傳到服務器:

    var client = new RestClient("http://localhost:8888/add");
client.Timeout = -1;
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddFile("image", "E:/1.jpg");
request.AddParameter("filepath", "images_store/1");
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);

此代碼由 Postman 本身生成,但是當我在我的應用程序中運行它時,它會給出 BadRequest

在此處輸入圖像描述

怎么了?

我在 postman 中看到您選擇了表單數據作為 ContentType,但在代碼中它顯示為 x-www-form-urlencoded。

哈貝你試過改變嗎?

暫無
暫無

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

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