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
1
vote
1 answer

What is the alternative for HttpContext.Response.OutputStream to use in WebAPI's HttpResponseMessage

I'm writing a WebAPI for handling PDF documents. It was written in a ashx page earlier implementing IHttpHandler and getting the context using HttpContext. I'm now writing it using WebAPI. In WebAPI we have HttpResponseMessage. For…
Noah Sunil
  • 45
  • 2
  • 8
1
vote
0 answers

Using [Authorize] attribute redirects to the login page

I am using Controller base class on my other controllers, but this specific controller is used to download a file from the server using wpf. I can download the file successfully without any problem if i dont put the [authorize] attribute but putting…
White Hat
  • 19
  • 5
1
vote
0 answers

Global variables per session

I have a problem dealing with global variables. I post XML's to my web, it does a POST for each file, in each load valid different fields and store information about it, with the global variables I am storing information of these. When testing from…
Zerart
  • 11
  • 2
1
vote
0 answers

Return HttpResponseMessage with a URL and post parameter

I have a WebAPI request made from my UI to WebAPI. This needs to return an HttpResponseMessage with a status code of HttpStatusCode.Moved, so that browser is redirected to another URL. My problem is that this target URL has to be a POST request,…
1
vote
1 answer

How do i Extract HTTPResponseMessage content from Console App

I am making a call to Web API from my Console App. I get HttpResponseMessage as the response. I am unable to read that message content. I tried var loginResult = await response.Content.ReadAsAsync(new List { new…
1
vote
1 answer

Return Null JSON Response instead of empty response {}

I have a WEB API that returns null data sometimes. I am expecting the below format as response {"cardResponse" : null} but I am getting {} as response. Any Idea? My method Definition looks like: public HttpResponseMessage Opeation(string input1,…
beast
  • 107
  • 12
1
vote
2 answers

HttpResponseMessage is IsSuccessStatusCode C#

I have the API in which I am trying to use PutAsync to update some fields. If the Put is successful I have message that will be sent as Response. But if the there are any exception when doing that I will have to send the exception message as…
Sid
  • 119
  • 1
  • 5
  • 16
1
vote
0 answers

How do I preserve foreign characterset from REST api when called by C# application

The response from my REST service returns JSON containing the correct Latin characters when I use Postman. When I call the same REST endpoint from my C# api the special characters used in Spanish or Portuguese are replaced with "?". Correct from…
1
vote
1 answer

How to set ContentType for unknown image extensions?

I have a service returning an image stream to be displayed in UI. How do I set the ContentType value for this as I do not know what the image type will be? It can be image/jpeg, image/png etc. fileContent.Content.Headers.ContentDisposition = new…
user5663970
  • 119
  • 2
  • 13
1
vote
3 answers

postAsync with header and content c#

I need to postAsync with header and content together. In order to get access to a website through Console Application in C#. I have my headers as an HttpHeader object with variable name header and my content named newContent as a string object with…
Puzzle
  • 25
  • 2
  • 2
  • 7
1
vote
0 answers

Store header key and value using HttpResponseMessage, GetAsynch

I have the following code and I want to store all keys and values of the header (i.e. cookie, session id, etc) in KeyValuepair type of an object. How can I accomplish that? CookieContainer cookies = new CookieContainer(); HttpClientHandler…
Puzzle
  • 25
  • 2
  • 2
  • 7
1
vote
1 answer

Why does response code return a different code?

In a WebAPI app, I throw and exception, which is caught. I then do this: catch (Exception e) { return Request.CreateResponse(HttpstatusCode.BadRequest); } On the caller side, the message is statuscode 400 as expected. When I do this…
4thSpace
  • 43,672
  • 97
  • 296
  • 475
1
vote
1 answer

HttpResponseMessage returning ByteArrayContent result - Preview document in chrome

I am trying to preview a file in Chrome but it keeps downloading. [HttpGet] [ResponseType(typeof(ByteArrayContent))] public HttpResponseMessage Download([FromUri] int uploadId) { try { Upload upload =…
Eliza
  • 13
  • 4
0
votes
0 answers

Getting and Sending cookies with HttpRequestMessage using vb.net

I have been through many articles here on StackOverflow and on Microsoft's own website, but I can't seem to find the correct, working solution. I make a request to a website, which it returns two cookies. I can get those cookies, as shown below. I…
0
votes
0 answers

HttpRsponseMessage to Excel is succesful in Postmna but has no data

I created method that aquires data and converts it to excel file. result, file and fileContent are properly set and have values, however there is no attachment or data in Postman: StatusCode: 200, ReasonPhrase: 'OK', Version: 1.1, Content:…
Simoneq14
  • 13
  • 2