Call works in Postman but not in C#

后端 未结 3 970
温柔的废话
温柔的废话 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:06

    RestClient constructor accepts URI that doesn't include userinfo

              userinfo       host      port
              ┌──┴───┐ ┌──────┴──────┐ ┌┴┐
      https://john.doe@www.example.com:123/forum/questions/?tag=networking&order=newest#top
      └─┬─┘   └───────────┬──────────────┘└───────┬───────┘ └───────────┬─────────────┘ └┬┘
      scheme          authority                  path                 query           fragment
    

    See: https://en.wikipedia.org/wiki/Uniform_Resource_Identifier

    In order to make it work with RestSharp, we'll need to do a little bit of extra work here:

    // Old:
    // var client = new RestClient("http://AJWKBLWT47VR26QWPNFCPJLXC6217F6F@presta.craftingcrow.com/api/categories"); 
    
    // New:
    var client = new RestClient("http://presta.craftingcrow.com/api/categories")
    {
        Authenticator = new HttpBasicAuthenticator("AJWKBLWT47VR26QWPNFCPJLXC6217F6F", "")
    };
    

提交回复
热议问题