小编Mik*_*ike的帖子

向Web引用添加授权标头

我正在尝试向客户端的Web服务发出请求(我不知道客户端的底层平台).我使用"添加Web引用"在Visual Studio 2010中使用了客户端的WSDL并生成了我的代理类(称为"ContactService").

我现在需要在我的服务请求中添加如下所示的授权标头.

Header=Authorization & Value=Basic 12345678901234567890
Run Code Online (Sandbox Code Playgroud)

(上面的"123456 ..."值只是占位符)

ContactService service = new ContactService();

//not sure if this is the right way - it's not working
WebClient client = new WebClient();
client.Headers.Add("Authorization", "Basic 12345678901234567890");            
service.Credentials = client.Credentials;

int contactKey = null;
try
{                
   contactKey = service.CreateContact("ABC", emailAddress, firstName, lastName, null);
}
Run Code Online (Sandbox Code Playgroud)

将授权标头添加到服务请求的正确方法是什么?

谢谢!

.net c# web-services web-reference request-headers

13
推荐指数
2
解决办法
4万
查看次数

标签 统计

.net ×1

c# ×1

request-headers ×1

web-reference ×1

web-services ×1