Adding Authorization Header to Web Reference

前端 未结 3 931

I\'m attempting to make requests to a client\'s web service (I don\'t know the underlying platform at the client). I\'ve consumed the client\'s WSDL in Visual Studio 2010 using

3条回答
  •  伪装坚强ぢ
    2021-02-07 11:34

    There are a couple of changes to make.

    Firstly, there is a handy constant HttpRequestHeader.Authorization.

    Secondly, are they expecting the header to be Base64 Encoded - this is normally required for basic authentication.

    WebClient.Headers.Add(HttpRequestHeader.Authorization, 
        "Basic " + Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes("12345678901234567890")));
    

提交回复
热议问题