Tag: http headers

使用HttpWebRequest收到截断的响应

我正在使用以下代码将HttpWebRequests创建到一个网站: public static HttpWebResponse SendGETRequest(string url, string agent, CookieContainer cookieContainer) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.UserAgent = agent; request.Method = “GET”; request.ContentType = “text/html”; request.CookieContainer = cookieContainer; return (HttpWebResponse)request.GetResponse(); } 几个网页都运行良好,直到我尝试使用新网页并且只收到页面的最后一部分。 这是收到的回复: 标题是正确的,并表示只发送接收的数据。 以下是请求和响应的标头: 请求: GET /Broker/Ops/FichaContratoJS.asp?nc=815044&IP=5&YY=2012&M=6&St=0&CC=FESX201206 HTTP/1.1 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.168 Safari/535.19 Content-Type: text/html Host: www.xxxx.com Cookie: […]

添加标头时在end_request中抛出exception

偶尔我会抛出这个exception(在elmah中可见) System.Web.HttpException: Server cannot append header after HTTP headers have been sent. System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> System.Web.HttpException: Server cannot append header after HTTP headers have been sent. at System.Web.HttpHeaderCollection.SetHeader(String name, String value, Boolean replace) at System.Web.HttpHeaderCollection.Add(String name, String value) at BettingOnYou.MvcApplication.Application_EndRequest() in /Global.asax.cs:line 55 这一行对应于: protected void […]

如何更改FLURL客户端的HTTP请求内容类型?

我正在使用flurl提交HTTP请求,这非常有用。 现在我需要将一些请求的“ Content-Type”标题更改为“application / json; odata = verbose” public async Task AddJob() { var flurlClient = GetBaseUrlForGetOperations(“Jobs”).WithHeader(“Content-Type”, “application/json;odata=verbose”); return await flurlClient.PostJsonAsync(new { //Some parameters here which are not the problem since tested with Postman }).ReceiveJson(); } private IFlurlClient GetBaseUrlForOperations(string resource) { var url = _azureApiUrl .AppendPathSegment(“api”) .AppendPathSegment(resource) .WithOAuthBearerToken(AzureAuthentication.AccessToken) .WithHeader(“x-ms-version”, “2.11”) .WithHeader(“Accept”, “application/json”); return url; } […]

如何在HTTP响应头中发送Cache-Control:no-cache?

净4和C#。 我需要在Web窗体页面的HTTP响应标头中设置发送到浏览器缓存控制( Cache-Control: no-cache )。 知道怎么做吗? 谢谢你的时间。

Content-Disposition文件名无法在IE上运行

我正在开发一个asp.net/c# web应用程序,允许用户查看和下载PDF文件。 当我点击一个文件时,我会在浏览器中可用的PDF阅读器中查看,当我保存它时,该文件应该保存为我通过标题传递的名称。 但这不是IE7和IE8中的行为 FileInfo f = new FileInfo(FileName); Response.ContentType = “application/pdf”; Response.AddHeader(“Content-Disposition”, “inline; filename=” + f.Name) 当我单击以保存文件时,我发送的文件名不用于保存文件,但正在使用URL中的aspx页面的文件名。 这是IE中的一个错误。 当我在Google Chrome上试用它时,一切正常。

当HTTP网页是html / text类型时,如何判断HTTP网页何时发生变化?

我正在尝试计算出算法,以判断网络上的非二进制文件是否已更改。 我打算去: LastModified datetime from header,然后如果这些不存在则回退到 来自标题的ContentLength 我发现,对于很多网站而言,HTML页面的LastModified实际上只是使用当前的DateTime,因此这种方法不起作用(即会导致页面总是在变化)我认为… ? 那么什么是好的算法呢? 怎么样? IF response.ContentType.StartsWith(“text/html”) <== or should this just be "text" THEN: Check based on comparing text content before & after ELSE: IF LastModified dates are OK Compare based on LastModified dates ELSE Compare based on ContentLength 谢谢

如何为来自BITS(后台智能传输服务)的Range请求设置正确的HTTP Response对象?

我需要实现一个可以向位发送文件的Web服务(后台智能传输服务)。 语言是ASP.NET(C#)。 我遇到的问题是“范围”的东西。 我的代码当前收到http请求(有效范围出现在0 – 4907的http标头中),随后在响应对象中输出一部分字节数组。 这是我的服务器代码: _context.Response.Clear(); _context.Response.AddHeader(“Content-Range”, “bytes ” + lower.ToString() + “-” + upper.ToString() + “//” + view.Content.Length.ToString()); _context.Response.AddHeader(“Content-Length”, upper.ToString()); _context.Response.AddHeader(“Accept-Ranges”, “bytes”); _context.Response.ContentType = “application/octet-stream”; _context.Response.BinaryWrite(data); _context.Response.End(); 接下来发生的事情是后续请求根本没有标题中的任何“范围”键……就像它要求整个文件一样! 不用说,位作业错误表明服务器响应无效。 我怀疑这一切都归结为服务器在响应对象中返回的标题…我很确定我在这里遵循协议。 如果有人可以帮忙解决这个问题,我将不胜感激……意思是……我会一直在寻找! 问候

发出http post请求以在WP7中发送JSON文件

我想JSON file from my WP7 device to my local server发送一个JSON file from my WP7 device to my local server 。 在iOS上,我使用了ASIHttpRequest库,我所做的是: //send json file , using ASIHttpClass NSURL *url = [NSURL URLWithString:urlStr]; ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url]; request.timeOutSeconds = TIME_OUT_SECONDS; [request setRequestMethod:@”PUT”]; NSString *credentials= [self encodeCredentials]; [request addRequestHeader:@”Authorization” value:[[NSString alloc] initWithFormat:@”Basic %@”,credentials]]; [request addRequestHeader:@”Content-Type” value:@”application/json; […]

如何在c#,ASP .NET中修改请求标头

我正在开发一个ASP .NET mVC项目,我必须更改HttpHeaders。 看到foolowing代码片段: WebRequest req= HttpWebRequest.Create(“myURL”); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); req.Headers.Add(“User-Agent”, “Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.15) Gecko/2009101601 Firefox/3.0.15 (.NET CLR 3.5.30729)”); req.Headers.Add(“Accept”, “text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8”); req.Headers.Add(“Accept-Language”, “en-us,en;q=0.5”); 这给了一个例外,即 必须使用适当的属性修改此标头。\ r \ nParameter name:name。 任何人都建议解决它

如何使用HttpClient在单个请求上设置HttpHeader

我有一个跨多个线程共享的HttpClient : public static class Connection { public static HttpClient Client { get; } static Connection() { Client = new HttpClient { BaseAddress = new Uri(Config.APIUri) }; Client.DefaultRequestHeaders.Add(“Connection”, “Keep-Alive”); Client.DefaultRequestHeaders.Add(“Keep-Alive”, “timeout=600”); Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(“application/json”)); } } 它有一些我放在每个请求上的默认标头。 但是,当我使用它时,我想为该请求添加标题: var client = Connection.Client; StringContent httpContent = new StringContent(myQueueItem, Encoding.UTF8, “application/json”); httpContent.Headers.Add(“Authorization”, “Bearer ” + accessToken); // <– […]