I want check the http traffic with Fiddler, but no any http traffic captured, my testing codes:
private static void ByRestSharp()
{
var restClient = new RestClient("https://jsonplaceholder.typicode.com");
var request = new RestRequest("posts", Method.GET);
var response = restClient.Get<List<Post>>(request);
Console.WriteLine("{0} posts return by RestSharp.", response.Data.Count);
}
But after I changed to use HttpClient, Fiddler can capture the http traffic, sample codes:
private static void ByHttpClient()
{
var httpClient = new HttpClient();
using (var req = new HttpRequestMessage(HttpMethod.Get, "https://jsonplaceholder.typicode.com/posts"))
using (var resp = httpClient.SendAsync(req).Result)
{
var json = resp.Content.ReadAsStringAsync().Result;
var users = SimpleJson.SimpleJson.DeserializeObject<List<Post>>(json);
Console.WriteLine("{0} posts return by HttpClient.", users.Count);
}
}
Is this a issue of RestSharp or Fiddler?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…