Arch
Arch

Reputation: 25

Creating a cURL like request in ASP.net

I got a request working perfectly when I created a request in cURL but I needed to make it c# code so I can add it to our system. This is the cURL request that I am trying to make a similar request in c# but had no luck on creating a correct one:

curl "https://someurl.com" -X PUT -d "@somefile.json" -H "Authorization: XXXXXX"

This is the current code that I have:

var httpContent = new StringContent(path + "somefile.json", Encoding.UTF8, "application/json");
putClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Authorization", "XXXXXX");
var response = await putClient.PutAsync(SOME_URL, httpContent);
var responseString = await response.Content.ReadAsStringAsync();

Thank you!!

Upvotes: 0

Views: 738

Answers (1)

Arch
Arch

Reputation: 25

I found out how to do it and is very easy. I modified this code:

var httpContent = new StringContent(jsonstring, Encoding.UTF8, "application/json");

It turns out that I don't really need to send a json file, sending a json string will be fine.

Upvotes: 1

Related Questions