错误401在C# [英] Error 401 in C#

查看:359
本文介绍了错误401在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作我的第一个应用程序适用于Windows 8,但我有一个问题,当我启动我的应用程序,我已经得到了错误响应状态code并不表明成功:

I'm working on my first app for Windows 8 but I have a problem, when I'm launch my app, I've got the error "Response status code does not indicate success:

401(所需授权)

所以,是的,我需要包括用户名和密码,但我不知道在我的code:

So yes, I need to include username and password but I don't know where in my code:

var fond = new HttpClient();
var reponse = await fond.GetStreamAsync("http://example.com/search/mario%20kart" + TitleNewsGrid.Text);    

那么,我包括在code中的用户名和密码?

So where I'm include the username and password in the code?

推荐答案

应该有一个证书 TransportSettings 例如

using (var client = new HttpClient())
{
    client.TransportSettings.Credentials = new System.Net.NetworkCredential("username", "pwd");
    ...
}

如果你没有访问 TransportSettings 属性,你需要使用 HttpClientHandler 代替。在复制code没点,已经有一个很好的例子<一href="http://stackoverflow.com/questions/10292730/httpclient-getasync-with-network-credentials">here.

If you don't have access to the TransportSettings property, you will need to use HttpClientHandler instead. No point in duplicating code, there is already a good example here.

这篇关于错误401在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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