使用凭据访问HTTPS URL

时间:2015-08-10 20:24:30

标签: c#

我有一个HTTPS网址,我正在尝试连接但无法继续获取未经授权的401。 我试图通过Web浏览器访问相同的URL(在家里和公司),并且能够连接到它。在浏览器中执行HTTPS URL(其中包含日期等参数)之后,会提示输入用户名和密码,当我输入时,它会回复xml。 我尝试在我的家用电脑上跟随代码片段并且工作正常但是当我在办公室网络中尝试相同时,它给了我407错误。之后我将代理代码嵌入其中,现在我没有得到407,而是我继续获得401.请帮助

家庭工作守则:

public static void WorkingCode()
{
    string URL = "https://webservice.XYZ.com/display/?start_date=2015-05-06&end_date=2015-05-07";
    Uri uri = new Uri(URL);
    WebClient wc = new WebClient();
    wc.Credentials = new NetworkCredential("username123", "Password123");
    string results;
    results = wc.DownloadString(uri);
    Console.Write(results);
    Console.Read();
}

PROXY组织内的代码:

public static void WorkingCode()
{
    string URL = "https://webservice.XYZ.com/display/?start_date=2015-05-06&end_date=2015-05-07";
    Uri uri = new Uri(URL);
    WebClient wc = new WebClient();
    wc.Credentials = new NetworkCredential("username123", "Password123");
    string results;

    /* PROXY CODE*/
    WebProxy myProxy = new WebProxy("frproxyseczom.PPP.com", 8080);
    myProxy.UseDefaultCredentials = true;
    wc.Proxy = myProxy;

    /*---------------*/
    results = wc.DownloadString(uri);

    Console.Write(results);
    Console.Read();
}

出于安全原因,我修改了一些细节,例如URL,用户名和密码。

1 个答案:

答案 0 :(得分:0)

您可能在代理代码中获得了401,因为您在Web代理地址中缺少“http://”。

相关问题