The separate console application works just fine and file gets downloaded through https call.
static void main() {MainAsync().Wait();}
static async Task MainAsync() {}
We can't do the async call with SSIS package script task. I was trying to find a way to make https via httpClient but always returns result error(marked in bold). Any way to fix this one? I see my script task project target framework is .net 4.5
public void Main()
{
GetData();
Dts.TaskResult = (int)ScriptResults.Success;
}
public static void GetData()
{
HttpClient client = new HttpClient();
var byteArray = Encoding.ASCII.GetBytes(string.Format("{0}:{1}", "TestUser", "TestPass"));
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
HttpResponseMessage response = client.GetAsync("https://Report/OutboundA00&format=csv").Result;
HttpContent content = response.Content;
if (response.IsSuccessStatusCode)
{
var responseContent = response.Content;
// by calling .Result you are synchronously reading the result
string responseString = responseContent.ReadAsStringAsync().Result;
//Console.WriteLine(responseString);
System.IO.File.WriteAllText("c:\\csv_outbound.csv", responseString);
}
}
Appreciate either fix the above or any other sample where I can call https url to download the data(it takes 2 minutes hence webclient wont work)
Many thanks,