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
3
votes
1 answer

Unable to cast object of type Newtonsoft.Json.Linq.JObject even though I am trying to cast to an object with matching properties

I am working with ASP.NET Core 2.0 in VS2017. I am trying to deserialize some JSON that is returned in an HttpResponseMessage but I am getting an "Unable to cast object of type..." exception. Here is the code that is…
3
votes
2 answers

WebAPI returns corrupted, incomplete file

I want to return an image from WebApi endpoint. This is my method: [System.Web.Http.HttpGet] public HttpResponseMessage GetAttachment(string id) { string dirPath = HttpContext.Current.Server.MapPath(Constants.ATTACHMENT_FOLDER); string path…
Tschareck
  • 4,071
  • 9
  • 47
  • 74
2
votes
3 answers

C# HttpClient GET returns 200 but an empty array

I've been trying to use HttpClient, to connect to an API. I'm able to send a GET request and recieve the desired data that I want from it through Postman and Fiddler, without issue. The issue is that the json file i get from the HttpClient is:…
2
votes
0 answers

.Net Core Receive FileContentResult from one API to Another

I am having trouble finding information on how to do this so I will ask here. The situation is that I have an API that has a response type of FileContentResult. I have another API that needs to receive this FileContentResult. So, I guess the real…
TopBanana9000
  • 818
  • 2
  • 14
  • 32
2
votes
1 answer

Skipping parent properly in JsonDeserializer

I am receiving an HttpResponseMessage that looks like this (data redacted): { "tracks" : { "href" : "{href_here}", "items" : [ { "album" : { //stuff here }, "name": "{name here}" }, { "album" : { …
Jessica
  • 1,621
  • 2
  • 18
  • 34
2
votes
2 answers

streamReader.ReadToEndAsync() changing message content

I have a .Net Core 3.1 Web API that needs to interact with an external service that is providing a multipart/related response from a WCF Service with attachments in the context as the below block. HTTP/1.1 200 OK Cache-Control:…
Simon Price
  • 3,011
  • 3
  • 34
  • 98
2
votes
0 answers

WebApi returns blank PDF file

I am using MigraDoc to generate PDF, it saves perfectly on the local machine, but when I send this file stream to webapi, browser opens it with blank content. var response = new HttpResponseMessage(HttpStatusCode.OK) { …
Shukhrat Raimov
  • 2,137
  • 4
  • 21
  • 27
2
votes
1 answer

How do I convert a string into an HTTP Response in C#?

{ "AdditionalProcessCardSwipeResponseData": null, "CustomerTransactionID": "", "ProcessCardSwipeOutputs": [ { "AdditionalProcessCardSwipeResponseData": null, "CardSwipeOutput": { …
Rickchip
  • 371
  • 1
  • 4
  • 12
2
votes
1 answer

How to access ResponseEntity in React App?

I have this React App which has back end as Spring Boot java application. Its login flow requires to redirect from App to third party servlet, and then this servlet calls our backend API with AUTH code, which after validation in backend must be…
2
votes
0 answers

HttpResponseMessage EnsureSuccessStatusCode() method internally

I need to remove EnsureSuccessStatusCode() method from my code and throw HttpRequestException manually. Looking at internals of EnsureSuccessStatusCode: public HttpResponseMessage EnsureSuccessStatusCode() { if (!this.IsSuccessStatusCode) …
SimonD
  • 1,441
  • 2
  • 18
  • 30
2
votes
1 answer

HttpResponse's content's length doesn't match the plain text

I'm making a post request with HttpRequestMessage/HttpResponseMessage. Everything is okay, I'm getting the response into a string whose length is correct as expected, but if I want to display the raw string, it just returns one question mark…
Dezv
  • 156
  • 1
  • 8
2
votes
1 answer

How to properly check http status code for HttpResponseMessage in C#?

complete novice at C# reporting in Lets say I have the following code HttpResponseMessage response = ... How would I check if the status code for response is a 403? The property StatusCode is an object - as opposed to an integer, So I am not quite…
AlanSTACK
  • 5,525
  • 3
  • 40
  • 99
2
votes
2 answers

HttpResponseMessage.Content.ReasAsString returns an empty string

I have a WS that I call like this: HttpResponseMessage response = await client.PostAsync(url, new StringContent(json)); the WS will throw an Exception (Forbidden) and in my Blazor application that made the PostAsync call, I will get an…
Ted
  • 19,727
  • 35
  • 96
  • 154
2
votes
1 answer

Downloading a csv file from Web API does not start

I have this sample code from different sources and I want to try it first before applying it to my code which is pretty similar to the samples I got. I have the following codes in my controller: [Route("getcsv")] [HttpGet] public…
ThEpRoGrAmMiNgNoOb
  • 1,256
  • 3
  • 23
  • 46
2
votes
3 answers

Jersey response's reason phrase is inconsistent in tomcat 7 and 8.5

I'm using Tomcat 8.5 in one server and Tomcat 7 in different server and I have the following jersey resource: @Path("main") public class MyResource…
Ori Marko
  • 56,308
  • 23
  • 131
  • 233
1
2
3
11 12