I want to make the following curl call in my C# console application:
curl -d "text=This is a block of text"
http://api.repustate.com/v2/demokey/score.json
I tried to do like the question posted here, but I cannot fill the properties properly.
I also tried to convert it to a regular HTTP request:
http://api.repustate.com/v2/demokey/score.json?text="This%20is%20a%20block%20of%20text"
Can I convert a cURL call to an HTTP request? If so, how? If not, how can I make the above cURL call from my C# console application properly?
Call cURL from your console app is not a good idea.
But you can use TinyRestClient which make easier to build requests :
Well, you wouldn't call cURL directly, rather, you'd use one of the following options:
HttpWebRequest
/HttpWebResponse
WebClient
HttpClient
(available from .NET 4.5 on)I'd highly recommend using the
HttpClient
class, as it's engineered to be much better (from a usability standpoint) than the former two.In your case, you would do this:
Also note that the
HttpClient
class has much better support for handling different response types, and better support for asynchronous operations (and the cancellation of them) over the previously mentioned options.Or in restSharp:
Below is a working example code.
Please note you need to add a reference to Newtonsoft.Json.Linq
Reference: TheDeveloperBlog.com