Mehran
Member
- Joined
- Aug 18, 2021
- Messages
- 7
- Programming Experience
- Beginner
Hello Good time !
I want to send a image file to the following address
I tested it with Postman and it works..
I wrote the following code
But I get the following error :"An exception occurred during a WebClient request."
Please note: I also use this code in older systems (.net 3.5,4) so I used WebClient
I want to send a image file to the following address
I tested it with Postman and it works..
I wrote the following code
C#:
try
{
string URI = "https://admin.asilasal.ir/api/Guestuploadimage";
string myParameters = "file=" + @"C:\Users\Administrator\Desktop\1.jpg";
using (WebClient wc = new WebClient())
{
wc.Headers[HttpRequestHeader.ContentType] = "multipart/form-data; boundary=<calculated when request is sent>";
wc.Headers.Set("Content-Length", "<calculated when request is sent>");
wc.Headers.Set("HOST", "<calculated when request is sent>");
wc.Headers.Set("User-Agent", "<PostmanRuntime/7.28.4>");
wc.Headers.Set("User-Agent", "*/*");
wc.Headers.Set("Accept", "*/*");
wc.Headers.Set("Accept-Encoding", "gzip, deflate, br");
wc.Headers.Set("Connection", "keep-alive");
string HtmlResult = wc.UploadString(URI, myParameters);
//MessageBox.Show(HtmlResult);
}
}
catch (Exception ex)
{
textBox1.Text = ex.Message;
}
But I get the following error :"An exception occurred during a WebClient request."
Please note: I also use this code in older systems (.net 3.5,4) so I used WebClient