TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
prasanna p
1.3k
470
103.9k
how to read Web APi csv file
Nov 18 2020 4:39 AM
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 Web 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.
for web Api login I wrote this code
var userName =
"
[email protected]
"
;
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();
For downloading file I used
this
code file
is
downloading but the HTML content
is
coming
in
the downloaded CSV file.
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);
}
how to do this?
Reply
Answers (
4
)
ASP.NET Core Razor - cascade dropdown from 4 tables
Cognito and ASP.NET C# problem