访问受保护的Web服务时的HTTP状态码401(未授权) [英] HTTP Statuscode 401 (unauthorized) when accessing secured webservice

查看:1073
本文介绍了访问受保护的Web服务时的HTTP状态码401(未授权)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




访问安全的第三方网络服务时,我得到的是401 HTTP状态码(未经授权)。在

浏览器中输入URL并手动输入用户名和密码时,将返回wsdl。所以用户名和密码应该是

没关系。


我正在使用这段代码:


商家myMerch = new Merchant();

myMerch.merchantIdentifier = merchantId;

myMerch.merchantName =" Merchant Name";


// WSE 2.0 Web服务接口

merchantinterfacedimeWse m_merch = new merchantinterfacedimeWse();

m_merch.Url = url;

m_merch.Credentials = new NetworkCredential(用户名,密码);


MerchantDocumentInfo [] docs = m_merch.getAllPendingDocumentInfo(myMerch," _GET_ORDERS_DATA_");


什么可以我知道吗?


谢谢,

Anton

Hi,

when accessing a secured 3rd party webservice i''m getting a 401 HTTP Statuscode (unauthorized). When entering the url in
a browser and entering the username and password manually, the wsdl is returned. So the username and password should
be ok.

I''m using this code:

Merchant myMerch = new Merchant();
myMerch.merchantIdentifier=merchantId;
myMerch.merchantName="Merchant Name";

// WSE 2.0 Webservice Interface
merchantinterfacedimeWse m_merch = new merchantinterfacedimeWse();
m_merch.Url = url;
m_merch.Credentials = new NetworkCredential(username,password);

MerchantDocumentInfo[] docs = m_merch.getAllPendingDocumentInfo(myMerch, "_GET_ORDERS_DATA_");

What can I do?

Thanks,
Anton

推荐答案

嗨Anton,


从你的描述中,你在.net应用程序中访问

external / 3rdparty webservice时遇到了一些问题,错误是

特定于安全认证,对吗?


根据错误消息,它表示一些未经身份验证或

未经授权的错误(401错误代码)。此外,在您提供的
的代码段中,您已使用networkCredential类构建安全性凭证并将其传递给webservice代理。目前,我想

确认以下事项:


**当你访问web服务asmx时,它是否提示

用户名/密码?


**这是外部网络服务的authenticatino模式(集成窗口

或基本身份验证)或者它是否托管在IIS服务器上?


对于.nett webservice代理,您可以使用CredentialCache类构建

客户端凭据并指定认证类型。例如


#use NTLM身份验证

==============

MyService.MyService ms = new MyService.MyService();


System.Net.NetworkCredential nc = new

System.Net.NetworkCredential(" username","密码"," domainame");


System.Net.CredentialCache cc = new System.Net.CredentialCache();

cc.Add(new Uri(ms.Url),NTLM,nc);


ms.Credentials = cc;

========= =======


这是我之前提到过的一个帖子:


#如何调用网络服务使用来自Web服务选项的NT身份验证
http://groups.google.com/group/micro...es.csharp/brow

se_thread / thread / b6ccba48133cb367 / 3d51bc6213805828


您需要确定什么是目标服务的身份验证阳离子模式和

然后为您的凭证指定正确的身份验证类型。


此致,


Steven Cheng


Microsoft MSDN在线支持主管

让我们的客户满意是我们的首要任务。我们欢迎您的意见和

有关我们如何改进我们为您提供的支持的建议。请

随时让我的经理知道您对服务水平的看法

提供。您可以直接向我的经理发送反馈:
ms****@microsoft.com


========================================== ========

通过电子邮件收到我的帖子通知?请参阅
http://msdn.microsoft .com / subscripti ... ult.aspx#notif

ications。


注意:MSDN托管新闻组支持服务是针对非紧急问题

如果社区或微软支持人员在1个工作日内做出初步回复是可以接受的。请注意,每个跟随

的响应可能需要大约2个工作日作为支持

专业人士与您合作可能需要进一步调查才能达到

最有效的分辨率。该产品不适用于需要紧急,实时或基于电话的交互或复杂的b $ b项目分析和转储分析问题的情况。这种性质的问题最好通过联系

Microsoft客户支持服务(CSS)处理
href =http://msdn.microsoft.com/subscriptions/support/default.aspx\"target =_ blank> http://msdn.microsoft.com/subscripti...t/default.aspx

======================================== ==========

此帖子按原样提供。没有保证,也没有赋予任何权利。

--------------------

日期:太阳,15 2008年6月10:00:01 +0200

来自:Anton< an *** @ newsgroups.nospam>

主题:访问安全时的HTTP状态码401(未经授权)

webservice




访问安全的第三方网络服务时我得到的是401 HTTP

状态代码(未经授权)。在

浏览器中输入网址并手动输入用户名和密码时,wsdl返回

。所以用户名和密码应该是

没关系。


我正在使用这段代码:


商家myMerch = new Merchant();

myMerch.merchantIdentifier = merchantId;

myMerch.merchantName =" Merchant Name";


// WSE 2.0 Web服务接口

merchantinterfacedimeWse m_merch = new merchantinterfacedimeWse();

m_merch.Url = url;

m_merch.Credentials = new NetworkCredential(用户名,密码);


MerchantDocumentInfo [] docs = m_merch.getAllPendingDocumentInfo(myMerch,

" _GET_ORDERS_DATA_");


我该怎么办?


谢谢,

Anton

Hi Anton,

From your description, you''re encountering some problem when accessing an
external/3rdparty webservice in your .net application, the error is
specific to security authentication, correct?

According to the error message, it indicate some unauthenticated or
unauthorized error(401 error code). Also, in the code snippet you
provided, you have used the networkCredential class to construct a security
credentials and pass it into webservice proxy. currently, I''d like to
confirm the following things:

** when you visit the webservice asmx, is it prompting dialog for
username/password?

** that''s the external webservice''s authenticatino mode( integrated windows
or basic authentication) or whether it is hosted on IIS server ot not?

For .nett webservice proxy, you can use CredentialCache class to construct
client credentials and specify authenticaiton type. e.g.

#use NTLM authentication
==============
MyService.MyService ms = new MyService.MyService();

System.Net.NetworkCredential nc = new
System.Net.NetworkCredential("username","password" ,"domainame");

System.Net.CredentialCache cc = new System.Net.CredentialCache();
cc.Add(new Uri(ms.Url),"NTLM",nc);

ms.Credentials = cc;
================

Here is a former thread I''ve mentioned this:

#How to call a web service using NT Authentication from Web Service Options
http://groups.google.com/group/micro...es.csharp/brow
se_thread/thread/b6ccba48133cb367/3d51bc6213805828

You need to make sure what''s the target service''s authentication mode and
then specify the correct authentication type for your credential.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
Date: Sun, 15 Jun 2008 10:00:01 +0200
From: Anton <an***@newsgroups.nospam>
Subject: HTTP Statuscode 401 (unauthorized) when accessing secured
webservice
Hi,

when accessing a secured 3rd party webservice i''m getting a 401 HTTP
Statuscode (unauthorized). When entering the url in
a browser and entering the username and password manually, the wsdl is
returned. So the username and password should
be ok.

I''m using this code:

Merchant myMerch = new Merchant();
myMerch.merchantIdentifier=merchantId;
myMerch.merchantName="Merchant Name";

// WSE 2.0 Webservice Interface
merchantinterfacedimeWse m_merch = new merchantinterfacedimeWse();
m_merch.Url = url;
m_merch.Credentials = new NetworkCredential(username,password);

MerchantDocumentInfo[] docs = m_merch.getAllPendingDocumentInfo(myMerch,
"_GET_ORDERS_DATA_");

What can I do?

Thanks,
Anton


嗨史蒂文,


感谢您的快速回复。第三方Web服务托管在Linux上。它不是.NET Web服务。


它使用基本身份验证。如果我正在Webbrowser中访问webservice url,则会提示

用户名/密码对话框。当我输入用户名和密码时,wsdl会显示在浏览器中。


使用CredentialCache指定基本身份验证没有用。我试过这段代码:


System.Net.NetworkCredential nc = new

System.Net.NetworkCredential(username,password,");

System.Net.CredentialCache cc = new System.Net.CredentialCache();

cc.Add(new Uri(m_merch.Url)," Basic",nc );

m_merch.Credentials = cc;


Steven Cheng [MSFT] schrieb:
Hi Steven,

thanks for you fast response. The 3rd party webservice is hosted on linux. It''s not a .NET Webservice.

It uses Basic Authentication. If I''m visting the webservice url in the Webbrowser it is prompting dialog for
username/password. When i enter username and password, the wsdl is displayed in the browser.

Using the CredentialCache to specify basic authentication didn''t help. I have tried this code:

System.Net.NetworkCredential nc = new
System.Net.NetworkCredential(username,password,"") ;
System.Net.CredentialCache cc = new System.Net.CredentialCache();
cc.Add(new Uri(m_merch.Url),"Basic",nc);
m_merch.Credentials = cc;


Steven Cheng [MSFT] schrieb:

您好Anton,


从您的描述中,您在.net中访问

external / 3rdparty webservice时遇到了一些问题应用程序,错误是

特定于安全验证,对吗?

根据错误信息,它表示一些未经验证或

未经授权的错误(401错误代码)。此外,在您提供的
的代码段中,您已使用networkCredential类构建安全性凭证并将其传递给webservice代理。目前,我想

确认以下事项:


**当你访问web服务asmx时,它是否提示

用户名/密码?


**这是外部网络服务的authenticatino模式(集成窗口

或基本身份验证)或者它是否托管在IIS服务器上?


对于.nett webservice代理,您可以使用CredentialCache类构建

客户端凭据并指定认证类型。例如


#use NTLM身份验证

==============

MyService.MyService ms = new MyService.MyService();


System.Net.NetworkCredential nc = new

System.Net.NetworkCredential(" username","密码"," domainame");


System.Net.CredentialCache cc = new System.Net.CredentialCache();

cc.Add(new Uri(ms.Url),NTLM,nc);


ms.Credentials = cc;

========= =======


这是我之前提到过的一个帖子:


#如何调用网络服务使用来自Web服务选项的NT身份验证
http://groups.google.com/group/micro...es.csharp/brow

se_thread / thread / b6ccba48133cb367 / 3d51bc6213805828


您需要确保什么是目标服务的身份验证模式和

然后为您的凭证指定正确的身份验证类型。


此致,


Steven Cheng


Microsoft MSDN在线支持主管


让客户满意是我们的首要任务。我们欢迎您的意见和

有关我们如何改进我们为您提供的支持的建议。请

随时让我的经理知道您对服务水平的看法

提供。您可以直接向我的经理发送反馈:
ms****@microsoft.com


========================================== ========

通过电子邮件收到我的帖子通知?请参阅
http://msdn.microsoft .com / subscripti ... ult.aspx#notif

ications。


注意:MSDN托管新闻组支持服务是针对非紧急问题

如果社区或微软支持人员在1个工作日内做出初步回复是可以接受的。请注意,每个跟随

的响应可能需要大约2个工作日作为支持

专业人士与您合作可能需要进一步调查才能达到

最有效的分辨率。该产品不适用于需要紧急,实时或基于电话的交互或复杂的b $ b项目分析和转储分析问题的情况。这种性质的问题最好通过联系

Microsoft客户支持服务(CSS)处理
href =http://msdn.microsoft.com/subscriptions/support/default.aspx\"target =_ blank> http://msdn.microsoft.com/subscripti...t/default.aspx

======================================== ==========

此帖子按原样提供。没有保证,也没有赋予任何权利。


--------------------

日期:Sun,2008年6月15日10:00:01 +0200

来自:Anton< an *** @ newsgroups.nospam>

主题:HTTP状态代码401(未经授权) )访问安全时

webservice





访问安全的第三方网络服务我是获得401 HTTP

状态代码(未经授权)。在

浏览器中输入网址并手动输入用户名和密码时,wsdl返回

。所以用户名和密码应该是

没关系。


我正在使用这段代码:


商家myMerch = new Merchant();

myMerch.merchantIdentifier = merchantId;

myMerch.merchantName =" Merchant Name";


// WSE 2.0 Web服务接口

merchantinterfacedimeWse m_merch = new merchantinterfacedimeWse();

m_merch.Url = url;

m_merch.Credentials = new NetworkCredential(用户名,密码);


MerchantDocumentInfo [] docs = m_merch.getAllPendingDocumentInfo(myMerch,

" _GET_ORDERS_DATA_");


我该怎么办?


谢谢,

Anton
Hi Anton,

From your description, you''re encountering some problem when accessing an
external/3rdparty webservice in your .net application, the error is
specific to security authentication, correct?

According to the error message, it indicate some unauthenticated or
unauthorized error(401 error code). Also, in the code snippet you
provided, you have used the networkCredential class to construct a security
credentials and pass it into webservice proxy. currently, I''d like to
confirm the following things:

** when you visit the webservice asmx, is it prompting dialog for
username/password?

** that''s the external webservice''s authenticatino mode( integrated windows
or basic authentication) or whether it is hosted on IIS server ot not?

For .nett webservice proxy, you can use CredentialCache class to construct
client credentials and specify authenticaiton type. e.g.

#use NTLM authentication
==============
MyService.MyService ms = new MyService.MyService();

System.Net.NetworkCredential nc = new
System.Net.NetworkCredential("username","password" ,"domainame");

System.Net.CredentialCache cc = new System.Net.CredentialCache();
cc.Add(new Uri(ms.Url),"NTLM",nc);

ms.Credentials = cc;
================

Here is a former thread I''ve mentioned this:

#How to call a web service using NT Authentication from Web Service Options
http://groups.google.com/group/micro...es.csharp/brow
se_thread/thread/b6ccba48133cb367/3d51bc6213805828

You need to make sure what''s the target service''s authentication mode and
then specify the correct authentication type for your credential.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
Date: Sun, 15 Jun 2008 10:00:01 +0200
From: Anton <an***@newsgroups.nospam>
Subject: HTTP Statuscode 401 (unauthorized) when accessing secured
webservice
Hi,

when accessing a secured 3rd party webservice i''m getting a 401 HTTP
Statuscode (unauthorized). When entering the url in
a browser and entering the username and password manually, the wsdl is
returned. So the username and password should
be ok.

I''m using this code:

Merchant myMerch = new Merchant();
myMerch.merchantIdentifier=merchantId;
myMerch.merchantName="Merchant Name";

// WSE 2.0 Webservice Interface
merchantinterfacedimeWse m_merch = new merchantinterfacedimeWse();
m_merch.Url = url;
m_merch.Credentials = new NetworkCredential(username,password);

MerchantDocumentInfo[] docs = m_merch.getAllPendingDocumentInfo(myMerch,
"_GET_ORDERS_DATA_");

What can I do?

Thanks,
Anton


Anton,
Anton,

访问安全的第三方网络服务时,我得到401 HTTP

状态代码(未经授权)。在浏览器中输入URL并手动输入用户名和密码时,将返回wsdl。

因此用户名和密码应该没问题。
when accessing a secured 3rd party webservice i''m getting a 401 HTTP
Statuscode (unauthorized). When entering the url in a browser and
entering the username and password manually, the wsdl is returned.
So the username and password should be ok.



看看实际流量,例如使用Fiddler

www.fiddlertool.com)


授权标题看起来好吗?即授权:基本<一些

base64编码的东西在这里>? (请注意,你也可以通过工具|文本编码/解码...来获得Fiddler解码

base64编码的东西。)


-

Arnout。

Take a look at the actual traffic, for instance using Fiddler
(www.fiddlertool.com).

Does the Authorization header look OK? I.e. "Authorization: Basic <some
base64-encoded stuff here>"? (Note that you can also have Fiddler decode
that base64-encoded stuff via "Tools | Text Encode/Decode...".)

--
Arnout.


这篇关于访问受保护的Web服务时的HTTP状态码401(未授权)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆