我正在尝试使用RSS feed URL生成XML格式的数据。我有一个例外:
远程服务器返回错误(400)错误的请求错误。
我正在使用SSIS包,并在控制流中创建了一个安全任务,我编写的脚本如下:
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;
}
答案 0 :(得分:0)
这可能是格式化凭证并将其传递到服务器的方式。 你可以试试吗?
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;
}