RestSharp json请求无效

时间:2017-04-16 10:23:01

标签: c# json rest restsharp

我想向HackerEarth api v3请求使用c#运行一些代码。

我尝试使用httpwebrequestwebclient,但我一直收到此错误:

Forbidden 403 error

所以我切换到了restsharp,现在又出现了另一个错误:

ArgumentMissingError: client_secret is needed!

我正在尝试使用下面的代码发出json请求,但是你可以看到它不起作用。

var client = new RestClient("https://api.hackerearth.com/v3/code/run/");
var request = new RestRequest(Method.POST);

var postdata = new
{
    client_secret = "***",
    async = "0",
    source = "print 'Hello World'",
    time_limit = "5",
    memory_limit = "262144"
};
var json = request.JsonSerializer.Serialize(postdata);

request.AddParameter("application/json; charset=utf-8", json, ParameterType.RequestBody);

IRestResponse response = client.Execute(request);
var content = response.Content;

Console.WriteLine(content);

我也尝试过unsing ironPython让它像他们那样做但是libriries存在一些问题,并且很难将asp.net mvc与ironPython结合起来。

使用restsharp制作json请求的正确方法是什么?

0 个答案:

没有答案