HttpClient authentication header not getting sent

前端 未结 4 1819
再見小時候
再見小時候 2020-12-05 18:06

I\'m trying to use an HttpClient for a third-party service that requires basic HTTP authentication. I am using the AuthenticationHeaderValue. Here

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-05 19:03

    Try setting the header on the client:

    DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.ASCII.GetBytes(String.Format("{0}:{1}", userName, password))));
    

    This works for me.

提交回复
热议问题