0
votes

I'm trying to generate data in XML Format by using a RSS feed URL. I got the exception:

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

I'm using a SSIS package and I created a Security Task in control Flow, the script I've written is as follows:

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;
}
1
Did you try without System.Net.ServicePointManager.SecurityProtocol - Isma
Hi. Yes i tried before i got The request was aborted: Could not create SSL/TLS secure channel. error. so i added System.Net.ServicePointManager.SecurityProtocol line in code - Preethi
Possibly missing header; see: stackoverflow.com/questions/22623664/… - LocEngineer
Thank you so much.. It is working as expected - Preethi

1 Answers

0
votes

It may be the way the credentials are being formatted and passed to the server. Can you try this?

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;
}