如何使用RESTSHARP状态代码错误44在我的Web API ASP.NET CORE 6.0文件中发送两个参数C#的参数
我的API中有接收文件,int和字符串参数的方法。另外,我还有一个桌面WPF应用程序(用C#编写),其中用户在选择一些选项后单击按钮,然后使用RestSharp创建对API的请求。
在此请求中,我需要转移.zip
文件,int和字符串参数。但是我得到了一个例外状态代码44。我在邮递员中测试了我的方法,它有效。请帮忙。
这是我的API方法所收到的:
[HttpPost]
[Route("AddFile")]
public async Task<IActionResult> AddFile(IFormFile file)
{
int comicsId = Int32.Parse(Request.Form["comicsId"]);
string issueName = Request.Form["issueName"].ToString();
这是桌面WPF应用程序代码:
private void BtnCreateAdd_OnClick(object sender, RoutedEventArgs e)
{
if (cbComicsName.SelectedItem == null || tbPath.Text.Trim().Length == 0 || tbIssueName.Text.Trim().Length==0)
{
}
else
{
var fileParameter = FileParameter.FromFile(tbPath.Text);
ComboBoxItem comboBoxItem = (ComboBoxItem)cbComicsName.SelectedItem;
var response = apiClient.Post(new RestRequest("download/addfile")
.AddParameter("comicsId",Convert.ToInt32(comboBoxItem.Tag))
.AddParameter("issueName",tbIssueName.Text)
.AddFile("file",fileParameter.GetFile,fileParameter.FileName,fileParameter.ContentType));
MessageBox.Show(response.Content);
}
}
这是错误,
System.Net.Http.HttpRequestException: Request failed with status code 44
这是我使用Postman与其成功代码
I have method in my API which receives a file, int and string params. Also I have a desktop WPF app (written in C#) where user after choosing some options click on button and app create request to API using RestSharp.
In this request I need to transfer a .zip
file, int and string params. But I get an exception status code 44. I test my method in Postman and it works. Please help.
This is what my API method receives:
[HttpPost]
[Route("AddFile")]
public async Task<IActionResult> AddFile(IFormFile file)
{
int comicsId = Int32.Parse(Request.Form["comicsId"]);
string issueName = Request.Form["issueName"].ToString();
This is the desktop WPF app code:
private void BtnCreateAdd_OnClick(object sender, RoutedEventArgs e)
{
if (cbComicsName.SelectedItem == null || tbPath.Text.Trim().Length == 0 || tbIssueName.Text.Trim().Length==0)
{
}
else
{
var fileParameter = FileParameter.FromFile(tbPath.Text);
ComboBoxItem comboBoxItem = (ComboBoxItem)cbComicsName.SelectedItem;
var response = apiClient.Post(new RestRequest("download/addfile")
.AddParameter("comicsId",Convert.ToInt32(comboBoxItem.Tag))
.AddParameter("issueName",tbIssueName.Text)
.AddFile("file",fileParameter.GetFile,fileParameter.FileName,fileParameter.ContentType));
MessageBox.Show(response.Content);
}
}
This is error
System.Net.Http.HttpRequestException: Request failed with status code 44
This is the way I use Postman to check method with it successful code
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论