Hi Friends,
To read data from our client API,first I am login into the url https://site.com by using username,password and location.
After login to get the data another Wep APi url is there https://site.com/users/reports/csv?location_id=42&from_date=2020-11-02&to_date=2020-11-05
After login we used this url the file is automatically downloading in the browser.
I want to read this csv file content and I need to insert the records into the database.
how to do this?
What I have tried:
I have tried the following code to login after that I am using the downloaded url.
var userName = "tec@gmail.com";
var passwd = "5CadcPT";
var url = "https://site.com";
var location= "Hyderabad";
var client = new HttpClient();
var authToken = Encoding.ASCII.GetBytes($"{userName}:{passwd}:{location}");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",
Convert.ToBase64String(authToken));
var result1 = await client.GetAsync(url);
var content = await result1.Content.ReadAsStringAsync();
and I used
stream = await response.Content.ReadAsStreamAsync();
var fileInfo = new FileInfo("reports_2020-11-10 08_14_12.csv");
using (var fileStream = fileInfo.OpenWrite())
{
await stream.CopyToAsync(fileStream);
}
File is downloading but the html content is coming in the csv file