I am writing HttpPost method and using FromBody attribute to send parameters.
[HttpPost]
public IActionResult TransformData([FromBody]IList<Employee> argument)
{
//logic - output stream is built here
return File(output, MediaTypeNames.Application.Xml, "output.xml");
}
From console application , I am trying to consume web API :
ObjectContent data = new ObjectContent(args.GetType(), args, new JsonMediaTypeFormatter());
using (HttpClient client = new HttpClient())
{
client.BaseAddress = new Uri("http://service:8080/");
MediaTypeWithQualityHeaderValue contentType = new MediaTypeWithQualityHeaderValue("application/json");
client.DefaultRequestHeaders.Accept.Add(contentType);
var response = client.PostAsync("api/controller", data);
response.Wait();
var responseContent = await response.Result.Content.ReadAsAsync<FileStreamResult>();
}
responseContent is null. Please help.
var net = new System.Net.WebClient();
var data = net.DownloadData(link);
var content = new System.IO.MemoryStream(data);
you save the content to your computer
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.