0

I need to translate the following curl call to a HttpClientcall:

curl:

curl -i -X GET "https://dev.wetransfer.com/v2/transfers/{transfer_id}/files/{file_id}/upload-url/{part_number}" \
  -H "Content-Type: application/json" \
  -H "x-api-key: your_api_key" \
  -H "Authorization: Bearer jwt_token"

My attempt at using Httpclient:

using (var client = new HttpClient())
{
 client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
 client.DefaultRequestHeaders.Add("x-api-key", My_Correct_ApiKey);
 client.DefaultRequestHeaders.Add("Authorization",My_Correct_Token);
 var xxx = client.GetAsync($"https://dev.wetransfer.com/v2/transfers/{response.Id}/files/{file.Id}/upload-url/{partNumber}").Result;
}

You will have to take my word that I filled in the parameters correctly. Now, the curl call works as expected and returns a Json message. The .Net code fails with a "Unsupported Media Type" response.

The curious thing is that the request does not have any Json-serialized content: all the info needed is packed into the Request Uri. (And as I understand it HttpClient does not support content on GET calls.)

Where am I going wrong?

Dabblernl
  • 15,831
  • 18
  • 96
  • 148

1 Answers1

0

The answer can be found here.

Basically, .Net does not allow you to add the Content-Type header on GET calls, because GET calls in .Net do not support Content! The link refers to a hack that removes this restriction for the Content-Type header.

Dabblernl
  • 15,831
  • 18
  • 96
  • 148