I have created a web service using .NET Web API. The web service part works great, I am able to send the zip file using Advanced REST Client. The problem is that I can't send the zip file programmatically. Here is the Advanced REST Client Request Headers:
I have try some things but without success. I am not posting what I have try, considering that this is basic stuff for web developers (I am desktop developer), but if it is necessary, I will. Thank you in advance.
EDIT: This is my recent version
private async void BeginUpdate(bool webserverStatus)
{
if (!webserverStatus) return;
var httpClient = new HttpClient();
var form = new MultipartFormDataContent();
var byteArray = File.ReadAllBytes("myUpdatePackage.zip");
form.Add(new ByteArrayContent(byteArray, 0, byteArray.Length), "myUpdatePackage", "myUpdatePackage.zip");
HttpResponseMessage response = await httpClient.PostAsync(@"http://localhost:9000/api/file/", form);
response.EnsureSuccessStatusCode();
httpClient.Dispose();
string sd = response.Content.ReadAsStringAsync().Result;
}
I realized that on Advanced REST Client, I was it using PUT, meanwhile on my C# application I call it using POST
HttpResponseMessage response = await httpClient.PostAsync(@"http://localhost:9000/api/file/", form);
So, here is the complete code:
private async void BeginUpdate(bool webserverStatus)
{
if (!webserverStatus) return;
var byteArray = File.ReadAllBytes("myUpdatePackage.zip");
var httpClient = new HttpClient();
var form = new MultipartFormDataContent();
form.Add(new ByteArrayContent(byteArray, 0, byteArray.Length), "myUpdatePackage", "myUpdatePackage.zip");
HttpResponseMessage response = await httpClient.PutAsync(@"http://localhost:9000/api/file/", form);
response.EnsureSuccessStatusCode();
httpClient.Dispose();
string sd = response.Content.ReadAsStringAsync().Result;
}
More details on this question
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.