RestSharp - Authorization Header not coming across to WCF REST service

前端 未结 3 726
攒了一身酷
攒了一身酷 2021-02-04 01:30

I am trying to call a locally hosted WCF REST service over HTTPS with basic auth.

This works and the Authorization header comes thru just fine and all is happy:

相关标签:
3条回答
  • 2021-02-04 01:33

    I used milano's answer to get my REST service call to work (using GET)

        Dim client2 As RestClient = New RestClient("https://api.clever.com")
    
        Dim request2 As RestRequest = New RestRequest("me", Method.GET)
    
        request2.AddParameter("Authorization", "Bearer " & j.access_token, ParameterType.HttpHeader)
    
        Dim response2 As IRestResponse = client2.Execute(request2)
        Response.Write("** " & response2.StatusCode & "|" & response2.Content & " **")
    

    The key was making sure there was a space after the word 'Bearer' but this may apply to any type of custom token authorization header

    0 讨论(0)
  • 2021-02-04 01:50

    You have to use ParameterType.HttpHeader parameter:

    request.AddParameter("Authorization", "data", ParameterType.HttpHeader);
    
    0 讨论(0)
  • 2021-02-04 01:55

    instead of adding the header 'manually' do the following:

    var client = new RestSharp.RestClient("https://localhost/MyService/MyService.svc/");
    client.Authenticator = new HttpBasicAuthenticator("UserA", "123");
    
    0 讨论(0)
提交回复
热议问题