0

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!!

2
  • 2
    What is the issue you are facing with C# code? Commented Nov 4, 2018 at 23:47
  • I'm getting INVALID_DATA from the server where I am calling the API. Commented Nov 5, 2018 at 0:17

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.