httpresponse

In IIS7.5 what module removes the body of a 400 Bad Request

对着背影说爱祢 提交于 2019-12-17 16:27:37
问题 I have written ASP.NET (4.0) code that sets the Response.StatusCode to 400 if the data posted to the server is in valid. I place useful information in the response body in the format that the request accepts header asks for. eg an html message saying "The date field is required...". In IIS7 (7.5.7600) on Windows 7 I get the correct html response back to the browser. In IIS7 (7.5.6000) on Windows 2008 I do not get the html body back, but only a text body with "Bad Request" as the content. Can

Web API: Content in HttpResponseMessage

旧巷老猫 提交于 2019-12-17 16:02:32
问题 In one of my Get request, I want to return an HttpResponseMessage with some content. Currently I have it working as follows: var header = new MediaTypeHeaderValue("text/xml"); Request.CreateResponse(HttpStatusCode.OK, myObject, header); However, since I am using the static Request, this becomes really difficult to test. From what I have read, I should be able to do the following: return new HttpResponseMessage<T>(objectInstance); However, seem to not be able to do this. Is it because I am

HttpCookieCollection.Add vs HttpCookieCollection.Set - Does the Request.Cookies collection get copied to the Response.Cookies collection?

霸气de小男生 提交于 2019-12-17 13:45:23
问题 I just want to clear this up. I know that if I have set a cookie on a previous request, it will show up in my Request.Cookies collection. I want to update my existing Cookie. Are the cookies from my Request.Cookies collection already copied to my Response.Cookies collection? Do I need to add a new cookie with the same key using Response.Cookies.Add() , or do I need to use Response.Cookies.Set() ? 回答1: There is a difference: Response.Cookies.Add() will allow duplicate cookies to be set http:/

What HTTP response headers are required

杀马特。学长 韩版系。学妹 提交于 2019-12-17 08:30:06
问题 What HTTP response headers are required to be sent from server to the client? I working to optimize the HTTP response headers to minimize the HTTP response overhead. I know "overhead" is somewhat exaggerated, but I like a clean output. I see a lot of websites, which sends redundant cache headers. e.g. It is redundant to specify both Expires and Cache-Control: max-age , or to specify both Last-Modified and ETag . Source HTTP/1.1: Header Field Definitions 回答1: It depends on what you define as

XlsxWriter object save as http response to create download in Django

坚强是说给别人听的谎言 提交于 2019-12-17 08:09:35
问题 XlsxWriter object save as http response to create download in Django? 回答1: I think you're asking about how to create an excel file in memory using xlsxwriter and return it via HttpResponse . Here's an example: try: import cStringIO as StringIO except ImportError: import StringIO from django.http import HttpResponse from xlsxwriter.workbook import Workbook def your_view(request): # your view logic here # create a workbook in memory output = StringIO.StringIO() book = Workbook(output) sheet =

Writing MemoryStream to Response Object

烂漫一生 提交于 2019-12-17 06:13:00
问题 I am using the following code to stream pptx which is in a MemoryStream object but when I open it I get Repair message in PowerPoint, what is the correct way of writing MemoryStream to Response Object? HttpResponse response = HttpContext.Current.Response; response.Clear(); response.AppendHeader("Content-Type", "application/vnd.openxmlformats-officedocument.presentationml.presentation"); response.AppendHeader("Content-Disposition", string.Format("attachment;filename={0}.pptx;",

Html.fromHtml() removes carriage-returns “&#xD”, “\n”

邮差的信 提交于 2019-12-14 03:52:58
问题 As a response I am getting a string which is windows .ini file each pair has &#xD in the end this is the carriage-return in Canonical XML. After String ini = Html.fromHtml(response).toString(); ini gets string with no line breaks instead of them white-spaces. How to keep line-breaks on their places? Response comes as <string xmlns="http://schemas.microsoft.com/2003/10/Serialization/"><?xml version="1.0" encoding="utf-8"?><Profile>[General] AutoRecoveryConversion=1 UpdateExistingBootScreen=0

c#: System.Web.HttpResponse class not available in intellisense

房东的猫 提交于 2019-12-14 03:52:18
问题 So I'm writing a program in C# Visual Studio 2013. At the top of my code, among my usings, I have: using System.Web; But when I try to use the line: HttpResponse httpResp = (HttpResponse)response; then Intellisense says there is no HttpResponse class, in spite of the fact that HttpResponse is part of the System.Web namespace according to this page: https://msdn.microsoft.com/en-us/library/system.web.httpresponse(v=vs.110).aspx Furthermore it doesn't give me any options as to what else I could

HTTP Request\Response Header Grammar

南楼画角 提交于 2019-12-13 19:16:28
问题 In the header of an HTTP request or response will the header keys be constant in terms of capitalization, between servers. I ask so I can expect in my code: (Using Fake Function names) Safe Precise Python Code for hdr in header.keys(): if 'content-length' == hdr.lower(): recv_more_data( header[hdr] ) # header[hdr] == Content-Length (5388) bytes break # Exit for loop when if statement is met. Code I Would Like To Use recv_more_data (header['Content-Length']) # I know to expect 'Content-Length'

I want from a servlet to add some plain text content and two headers to the HttpServletResponse

我与影子孤独终老i 提交于 2019-12-13 14:44:39
问题 I want to add some plain text and two headers to the HttpServletResponse , the code is the following: resp.setContentType("text/plain"); resp.getWriter().write(messages.get(next).getContent()); resp.addHeader("success", "yes"); resp.addHeader("hasnext", ((Boolean)hasNext).toString()); The problem I encounter is that sending the content prevents the sending of the headers. If I don't write the content the headers are received fine, if I include the text they don't. What is the problem ? 回答1: