远程服务器返回错误 (400) 错误请求

the remote server returned an error (400) bad request

我正在尝试使用 RSS 提要 URL 以 XML 格式生成数据。我得到了异常:

Remote server returned an error (400) bad request error.

我使用的是SSIS包,我在control Flow中创建了一个Security Task,我写的脚本如下:

public bool DownloadFeed()
{
    string user = "xxx";
    string password = "pwd";

    WebClient web = new WebClient();
    System.Net.WebClient wc = new System.Net.WebClient();
    wc.Credentials = new System.Net.NetworkCredential(user, password);
    System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Ssl3 | 
                                                        SecurityProtocolType.Tls | 
                                                        SecurityProtocolType.Tls11 | 
                                                        SecurityProtocolType.Tls12;
    wc.DownloadFile(@"https://Entered RSS Feed URL here", @"H:\import\Test.xml");
    return true;
}

这可能是凭据被格式化并传递到服务器的方式。 你能试试这个吗?

using System.Net;

public bool DownloadFeed()
{
    string user = "xxx";
    string password = "pwd";

    System.Net.WebClient wc = new System.Net.WebClient();
    string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(user + ":" + password));
    wc.Headers[HttpRequestHeader.Authorization] = "Basic " + credentials;
    System.Net.ServicePointManager.SecurityProtocol =      System.Net.SecurityProtocolType.Ssl3 | 
                                                    SecurityProtocolType.Tls | 
                                                    SecurityProtocolType.Tls11 | 
                                                    SecurityProtocolType.Tls12;
    wc.DownloadFile(@"https://Entered RSS Feed URL here", @"H:\import\Test.xml");
    return true;
}