2

How do I do something simple as :

curl -X POST --data-binary '{"a":"b"}' --location "$URL"

I am working on Xamarin, c#

I am having problems with the dependecies.

demonplus
  • 5,613
  • 12
  • 49
  • 68
  • Why don't you use HttpClient ? https://msdn.microsoft.com/en-us/library/system.net.http.httpclient.postasync(v=vs.118).aspx – wishmaster May 03 '16 at 00:16

1 Answers1

3

You could use HttpClient by adding a system reference to System.Net.Http. Use the following sample code to create a client and submit the same call. Note that you could use another framework for converting class types into JSON text like Json.NET. Note that the following example shows how to construct HttpClient, but you should not dispose of the instance and track it elsewhere.

var client = new HttpClient()

string content = "{\"a\":\"b\"}";
StringContent httpContent = new StringContent(content);

var response = await client.PostAsync("$URL", httpContent);

if (response.IsSuccessStatusCode)
{
    var responseContent = await response.Content.ReadAsStringAsync();
    // Show response. 
}
else
{
    // Show error.
}
joncloud
  • 757
  • 5
  • 14