'How to send on my Web Api ASP.Net Core 6.0 file with two params from WPF app C# using RestSharp STATUS CODE ERROR 44
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|