Get JSON response using RestSharp

后端 未结 4 1520
长发绾君心
长发绾君心 2021-01-08 00:40

I\'m new to C# and I\'m trying to get the JSON response from a REST request using RestSharp; The request I want to execute is the following one : \"http://myurl.com/ap

4条回答
  •  佛祖请我去吃肉
    2021-01-08 01:06

    Try:

    var client = new RestClient("http://myurl.com/api/");
    
    var request = new RestRequest("getCatalog?token={token}", Method.GET); 
    
    request.AddParameter("token", "saga001", ParameterType.UrlSegment);   
    
    // request.AddUrlSegment("token", "saga001"); 
    
    request.OnBeforeDeserialization = resp => { resp.ContentType = "application/json"; };
    
    var queryResult = client.Execute(request);
    
    Console.WriteLine(queryResult.Content);
    

提交回复
热议问题