HttpWebRequest无法在第一篇文章中进行身份验证 [英] HttpWebRequest fails to authenticate on first post

查看:67
本文介绍了HttpWebRequest无法在第一篇文章中进行身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常基本的Http Web请求,我正在使用基本身份验证执行(请参阅下面的简单代码)。我遇到的问题是我在GetResponse上得到了一个ProtocolViolation WebException(Section = ResponseStatusLine)。执行
以太网跟踪会显示两条源自客户端的HTTP消息,第一条没有身份验证详细信息,第二条消息包含身份验证详细信息。服务器以不可避免的未经授权的响应
响应第一个请求,但是对第二个帖子做出了很好的响应,但是引发了WebException,所以我从来没有看到来自服务器的有效响应。我已经打开useUnsafeHeaderParsing,但这没有任何效果。该服务器是Windows CE 5.0设备,它支持NTLM和
基本身份验证。我可以根据需要提供更多信息。

I have a very basic Http web request that I am performing using Basic authentication (see simplied code below). The problem I am running into is that I get a ProtocolViolation WebException (Section=ResponseStatusLine) on the GetResponse. Performing a ethernet trace reveals two HTTP messages originating from the client, the first without the authentication details and the second with the authentication details. The server reponds to the first request with the inevitable unauthorized response but responds fine to the second post, however the WebException is raised so I never see the valid response from the server. I've turned on useUnsafeHeaderParsing but that has no effect. The server is a Windows CE 5.0 device which supports both NTLM and Basic authentication. I can provide further information as required.

非常感谢任何帮助。

干杯

贾斯汀

UriBuilder ^ uri =
gcnew UriBuilder( " http" ,strHostName);

UriBuilder^ uri = gcnew UriBuilder("http", strHostName);

uri-> Path = strUriPath;

NetworkCredential ^ nwCreds =

NetworkCredential^ nwCreds =

gcnew NetworkCredential(strUserName ,strPassword );

gcnew NetworkCredential(strUserName, strPassword);

CredentialCache ^ cc =

CredentialCache^ cc =

gcnew CredentialCache();

gcnew CredentialCache();

cc-> Add(uri-> Uri,

cc->Add(uri->Uri,

" Basic" ,nwCreds);

"Basic", nwCreds);

HttpWebRequest ^ webRequest =

HttpWebRequest^ webRequest =

dynamic_cast < HttpWebRequest ^>(WebRequest :: Create(uri-> Uri));

dynamic_cast<HttpWebRequest^>(WebRequest::Create(uri->Uri));

webRequest-> Credentials = cc;

webRequest->Credentials = cc;

HttpWebResponse ^ webResponse = dynamic_cast < HttpWebResponse ^>(webRequest-> GetResponse();

 

推荐答案

返回的授权标题是什么?有没有比较其他来源的跟踪Internet Explorer?

What are the Authorization Headers being returned?  Have you compared the trace from another source like Internet Explorer?


这篇关于HttpWebRequest无法在第一篇文章中进行身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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