OOB 应用程序中的请求缺少凭据

发布于 2024-10-18 14:44:38 字数 533 浏览 1 评论 0原文

我正在编写一个简单的 Silverlight 应用程序,其中包含以下代码,我认为这是非常标准的:

WebRequest.RegisterPrefix("http://", WebRequestCreator.ClientHttp);
var request = new WebClient();

var cred = new NetworkCredential(Server.UserName, Server.Password);
request.Credentials = cred;
request.UseDefaultCredentials = false;

request.DownloadStringCompleted += TestServerCompleted;
var uri = new Uri(Server.GetRequestUrl(Methods.ping));
request.DownloadStringAsync(uri);

然而,当我在 Fiddler 中查看请求时,标头中没有添加任何凭据。我缺少什么?那里不应该有一个“授权:基本...”标题吗?

I'm writing a simple Silverlight application in which I have the following code, which I think is pretty standard:

WebRequest.RegisterPrefix("http://", WebRequestCreator.ClientHttp);
var request = new WebClient();

var cred = new NetworkCredential(Server.UserName, Server.Password);
request.Credentials = cred;
request.UseDefaultCredentials = false;

request.DownloadStringCompleted += TestServerCompleted;
var uri = new Uri(Server.GetRequestUrl(Methods.ping));
request.DownloadStringAsync(uri);

Yet when I view the request in Fiddler, no credentials are added to the headers. What am I missing? Shouldn't there be an "Authorization: Basic ..." header in there?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

末骤雨初歇 2024-10-25 14:44:38

尝试这样的事情。

        HttpWebRequest.RegisterPrefix("http://", WebRequestCreator.ClientHttp);
        HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
        req.UseDefaultCredentials = false;
        req.Credentials = ew NetworkCredential(Server.UserName, Server.Passwor

        req.ContentType = "text/xml;charset=\"utf-8\"";
        req.Accept = "text/xml";
        req.Method = "POST";
        return req;

        req.BeginGetResponse((IAsyncResult asynchronousResultResponse) =>
            {
                try
                {
                    HttpWebRequest requestResponse = (HttpWebRequest)asynchronousResultResponse.AsyncState;
                    HttpWebResponse response = (HttpWebResponse)requestResponse.EndGetResponse(asynchronousResultResponse);
                    Stream streamResponse = response.GetResponseStream();
                    StreamReader streamRead = new StreamReader(streamResponse);
                    string responseString = streamRead.ReadToEnd();

                    //Your response is here in responseString

                    streamResponse.Close();
                    streamRead.Close();
                    response.Close();
                }
                catch (Exception e)
                {
                    Callback(null, e);
                }
            }, webRequest);

我希望它能有所帮助,即使是两个月后......

Try with something like this.

        HttpWebRequest.RegisterPrefix("http://", WebRequestCreator.ClientHttp);
        HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
        req.UseDefaultCredentials = false;
        req.Credentials = ew NetworkCredential(Server.UserName, Server.Passwor

        req.ContentType = "text/xml;charset=\"utf-8\"";
        req.Accept = "text/xml";
        req.Method = "POST";
        return req;

        req.BeginGetResponse((IAsyncResult asynchronousResultResponse) =>
            {
                try
                {
                    HttpWebRequest requestResponse = (HttpWebRequest)asynchronousResultResponse.AsyncState;
                    HttpWebResponse response = (HttpWebResponse)requestResponse.EndGetResponse(asynchronousResultResponse);
                    Stream streamResponse = response.GetResponseStream();
                    StreamReader streamRead = new StreamReader(streamResponse);
                    string responseString = streamRead.ReadToEnd();

                    //Your response is here in responseString

                    streamResponse.Close();
                    streamRead.Close();
                    response.Close();
                }
                catch (Exception e)
                {
                    Callback(null, e);
                }
            }, webRequest);

I Hope it can help, even 2 months later...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文