Call works in Postman but not in C#

后端 未结 3 928
温柔的废话
温柔的废话 2021-01-26 13:02

I am trying to make a call to below URL and it works just fine in Browser (Chrome) and also in Postman, but for some reason, it doesn\'t work in C#.

Working in b

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-26 13:04

    Thanks to Joshua & Vhoang!

    It's working after I changed code to below:

    var client = new RestClient("http://presta.craftingcrow.com/api/categories"); 
    var request = new RestRequest(Method.GET);
    request.AddHeader("cache-control", "no-cache");
    request.AddHeader("Authorization", "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes("AJWKBLWT47VR26QWPNFCPJLXC6217F6F:"));
    IRestResponse response = client.Execute(request);
    

    There was no need to add user-agent or include key in the hostname (URL)

提交回复
热议问题