A component of ASP.NET for creating RESTful web services that support HTTP-based communication between clients and servers.
Hi @Peter Liang ,
Thanks for reaching out.
For sharing data between your server and client app, it depends on what you want to achieve.
- Structured data (like a list of items): The easiest and most common way is to send it as JSON through your API. The client can then read it directly and use it in the app, no files needed.
- Text files (logs, reports, or exports):
If you specifically want the client to download or store the data as a file, your server can send it as a text file, and the client can fetch it and save or display it. For example: Server side (ASP.NET Core):
.NET client example:app.MapGet("/download", async context => { var content = "Hello from server!\nThis is a sample text file."; context.Response.ContentType = "text/plain"; await context.Response.WriteAsync(content); });
Browser (JavaScript) download example:using var client = new HttpClient(); var text = await client.GetStringAsync("https://yourserver.com/download"); Console.WriteLine(text);fetch("https://yourserver.com/download") .then(response => response.text()) .then(data => { const blob = new Blob([data], { type: 'text/plain' }); const link = document.createElement('a'); link.href = URL.createObjectURL(blob); link.download = "sample.txt"; link.click(); });
Note: Treat these code snippets as examples only - adjust them to fit your project structure and requirements.
Hope this helps! If my answer was helpful, I would greatly appreciate it if you could follow the instructions here so others with the same problem can benefit as well.