Questions tagged [httpresponsemessage]

HttpResponseMessage refers to the C# public class that represents an HTTP response message including the status code and data. Use this tag for questions related to the public class.

HttpResponseMessage refers to the C# public class that represents an HTTP response message including the status code and data. Use this tag for questions related to the public class.

168 questions
2
votes
1 answer

Parsing CSV from HttpResponseMessage using CSVHelper

Currently I am using a two step approach to fetch data from the Web Api and deserialize the CSV records into objects. var response = await httpClient.GetAsync(queryString); using (var reader = new StreamReader(await…
2
votes
0 answers

How do I get the model state from a HTTPRequestResponse from within a console application

I have an APS.NET Core 2.0 API that I am writing a test client for. The test client is a console application. I want to be able to read and display any errors returned from may API call that would be in the model state. In my API, if the model is…
2
votes
1 answer

GetAsync : not returning HttpResponseMessage

The apps should receive httpresponsemessage from LoginUser() but it becomes not responding. private void button1_Click(object sender, EventArgs e) { if (LoginUser(tUser.Text, Password.Text).Result.IsSuccessStatusCode) { …
1
vote
2 answers

How correctly return string content from Web APIs service on ASP.Net

I am developing a Web API service on ASP.NET (C#). [HttpPost, Route("add_role")] public async Task addRole(string roleName, string roleDescription) { var response = new HttpResponseMessage(HttpStatusCode.OK) { …
1
vote
2 answers

How to throw error (Bad Request) in void method in Web API

How to throw error (Bad Request) in void method in Web API public async Task UpdateRecord([FromBody] UpdateRecord model) { try { await _recordService.UpdateRecord(model); } catch (Exception ex) { var message = new…
Earth
  • 3,477
  • 6
  • 37
  • 78
1
vote
1 answer

How to get string response from generic asyn method

I am working on application which I have implemented a generic method which gets me response and serialize that response into response model. I am checking for error codes where I need to get the reason phrase which I want to return and to show to…
1
vote
2 answers

c# httpclient unable to read post response as json

I can't get my dotnet web api (v. 5.0) to read the json response from another API. It insists on 'decorating' the string with \ and removing quotes. I suspect it assumes the returned content is in a certain format and then tries to 'deserialize' the…
user1538142
  • 87
  • 1
  • 7
1
vote
0 answers

Deserialize HttpResponseMessage of Soap:Envelope to C# Object

I'm calling Soap method and receiving HttpResponseMessage as below : HttpResponseMessage createResponse = await ExecuteMyEndPoint(endpoint, requestXMLstring, client); And reading that as a String Response: string responseMessage = await…
Unknown Coder
  • 1,510
  • 2
  • 28
  • 56
1
vote
1 answer

HttpClient.SendAsync on Blazor WASM returns empty HttpResponseMessage although Fiddler shows that correct response was received

My Blazor page code: private async Task OnSendSMSClick() { var request = new HttpRequestMessage(HttpMethod.Post, baseAddress); request.SetBrowserRequestMode(BrowserRequestMode.NoCors); …
1
vote
0 answers

Dispose HttpResponseMessage is it good practice?

I am asking this question cause i recently discover that it is not good practice to dispose HttpClient in each request. In other hand it's better to use one instance in whole application. So my question is, if it is better or not to dispose…
1
vote
1 answer

C# how can I get a count of Json with several levels

I have a json like this one that comes from an api. I´m using oauth2 so i got the token, then I request the data. I want to count the name inside resources, to know how many are. { "startDate": "2019-06-23T16:07:21.205Z", "endDate":…
1
vote
2 answers

C# WEB API response downloads 0 size file

My below API action is supposed to send a zip file (max 100mb) as the result. There are no errors thrown in the code, however the file downloaded is 0 size. I checked the content length and there is value in the content length. what could be the…
Sin
  • 1,836
  • 2
  • 17
  • 24
1
vote
1 answer

Convert an object to Json in ASP.net Core

I am trying to convert and object "Persona" to a json string in .net Framework 4 and i need help. I have tried this (using System.Text.Json) public HttpResponseMessage Get(int id){ HttpResponseMessage response = new…
cgratelli
  • 75
  • 1
  • 11
1
vote
0 answers

Return file with non-latin characters from asp.net webAPI

HttpResponseMessage returning File from webApi with gibberish characters. I tried setting encoding on header but not helping. var dataBytes = File.ReadAllBytes(path); string fileName = Path.GetFileName(path); var dataStream = new…
Emc
  • 11
  • 3
1
vote
2 answers

How to Return Files (PDF) From asp.net web api 2

I would like to get pdf file from asp.net web api 2 / c# here is my Controller [JwtAuthentication] [HttpGet] [Route("Document")] public IHttpActionResult GetDocument([FromUri]int IdDocument, [FromUri]int ContentFileType) { string filePath =…
1 2
3
11 12