标签: http-headers

从Symfony行动发送附件/下载文件

我正在尝试通过操作传递CSV文件.响应中的mime类型仍显示为text/html.有人可以帮忙吗?谢谢

        //$this->setLayout(false);
        //$this->getUser()->shutdown();
        //sfConfig::set('sf_web_debug', false);
        $response = $this->getContext()->getResponse();
        $response = $this->getResponse();
        $response->clearHttpHeaders();
        $response->setHttpheader('Pragma: public', true);
        $response->addCacheControlHttpHeader('Cache-Control', 'must-revalidate');
        $response->setContentType('application/octet-stream', true);
        $response->setHttpHeader('Content-Description', 'File Transfer');
        $response->setHttpHeader('Content-Transfer-Encoding', 'binary', true);
        $response->setHttpHeader('Content-Length', filesize($file_path));
        $response->setHttpHeader('Content-Disposition', 'attachment; filename="' . $file_name . '"');
        $this->getResponse()->sendHttpHeaders();
        //$response->setContent(file_get_contents($file_path));
        //readfile($file_path);
        $this->renderText(file_get_contents($file_path));
        //return sfView::NONE;

        return sfView::HEADER_ONLY;
Run Code Online (Sandbox Code Playgroud)

相信我,在到达这里之前,我的搜索结果都是紫色的.正如你可以看到上面的所有排列和组合,我仍然无法实现这一点!

php attachment download http-headers symfony-1.4

1
推荐指数
1
解决办法
7203
查看次数

为什么即使缺少Access-Control-Allow-Headers,CORS请求也会成功?

Opera文档引用(我找到的第一个链接):

标准或自定义标头是Access-Control-Allow-Headers的适当值.要使跨源请求成功,其值必须匹配(或包含)Access-Control-Request-Headers标头的值.

我正在使用jQuery发送请求.如果我评论出来setRequestHeader:

$(function() {            
    $.ajax({
        url: 'http://silex.local/users',
        method: 'GET',
        beforeSend : function(req) {
            //req.setRequestHeader('Authorization', 'FID ds7sd6:32n8942b3672n2');
        }
    });
});
Run Code Online (Sandbox Code Playgroud)

它应该不起作用,因为服务器响应:

HTTP/1.0 200 OK
Date: Sat, 11 Aug 2012 02:15:14 GMT
Server: Apache/2.2.22 (Win32) PHP/5.3.14
X-Powered-By: PHP/5.3.14
Cache-Control: no-cache
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, PUT, PATCH, DELETE
Access-Control-Allow-Headers: Authorization
Connection: close
Content-Type: application/json; charset=utf-8
Run Code Online (Sandbox Code Playgroud)

客户请求时:

GET http://silex.local/users HTTP/1.1
Host: silex.local
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20100101 Firefox/14.0.1
Accept: */*
Accept-Language: …
Run Code Online (Sandbox Code Playgroud)

jquery http http-headers cors

1
推荐指数
1
解决办法
3224
查看次数

带有POST或PUT的jQuery.ajax没有IE8和IE9的响应头

我注意到使用IE8和IE9,如果我使用带有POSTPUT谓词的jQuery.ajax()调用我的RESTful API ,那么我不会在jqXHR中找回任何响应头.但是,GET请求按预期工作.

此行为与所有其他浏览器不同.我已经确认Chrome,FF,Opera和Safari都会在POST和PUT请求的响应中返回完整的预期标头集.只有IE8和IE9似乎在地板上扔标题.(我没有检查的一件事是HEAD请求会发生什么.)

我已经用Fiddler验证了标题实际上是通过线路进行的,所以问题出在jQuery本身或IE8和IE9上.

这是一个已知的问题?如果是这样,是否有解决方法.我可以在jQuery中重载/覆盖某些内容以保留POST和PUT后的头文件吗?我目前的解决方法是在成功回调中使用GET简单地重新获取修改后的数据,因为IE8和IE9不会混淆GET操作的头文件.

这是我基于jQuery的主要AJAX工作方法的片段:

    $.ajax({
        url: String.format(um.proxy.url, url),
        type: ajaxParams.verb,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        data: String.format('{0}', ajaxParams.jsonData),
        headers: mapOfHeaders,
        success: function (data, textStatus, jqXHR) {
            //...
        },
        error: function (msg, textStatus, errorThrown) {
            //...
        }
    });
Run Code Online (Sandbox Code Playgroud)

ajax jquery xmlhttprequest http-headers jqxhr

1
推荐指数
1
解决办法
3137
查看次数

如何用PHP渲染远程图像?

这是一个jpg: http://i.stack.imgur.com/PIFN0.jpg

stackoverflow logo jpg

让我们说我喜欢这个渲染 /img.php?file_name=PIFN0.jpg

这是我试图让这项工作的方式:

/sample.php

<p>Here's my image:</p>
<img src="/img.php?file_name=PIFN0.jpg">
Run Code Online (Sandbox Code Playgroud)

/img.php

<?php
    $url = 'http://i.stack.imgur.com/' . $_GET['file_name'];
    header('Content-type: image/jpeg');
    imagejpeg($url);
?>
Run Code Online (Sandbox Code Playgroud)

我希望/sample.php能够显示图像.但这不起作用.我得到的只是一张破碎的图像.我究竟做错了什么?

php image header http-headers

1
推荐指数
2
解决办法
1万
查看次数

在流星中访问入站HTTP标头?

我正在开发一个依赖于浏览器在HTTP头中发送的数据的应用程序(并且没有办法解决这个问题).这也恰好是我第一次使用node.js的东西,所以我很可能完全错过了一些简单的东西!

基本上我想要做的是从客户端调用服务器上的方法,并在该方法中读取客户端发送的HTTP头.

http-headers node.js meteor

1
推荐指数
1
解决办法
547
查看次数

在退出时清除缓存以防止在注销后返回登录页面或上一页

这已经困扰了我一个星期了.好吧,我非常需要在用户成功登录后清除登录页面的缓存,并防止用户在按下后退按钮后退出后查看上一页.我尝试在codeigniter中添加此代码(索引页面和登录页面),但仍然没有任何反应

header("Cache-Control: no-cache, must-revalidate");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Pragma: no-cache");
Run Code Online (Sandbox Code Playgroud)

以及这一个:

<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<META HTTP-EQUIV="EXPIRES" CONTENT="01 Jan 1970 00:00:00 GMT">
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
Run Code Online (Sandbox Code Playgroud)

我已经在考虑在后台运行的同步任务来检查会话但是我在AJAX中并不是那么好.那么我想要的就是让它像使用轨道上的红宝石一样简单Cache-Control: no-cache.顺便说一下,我也没有关于ruby的知识,但看到代码让我想知道为什么在codeigniter中没有像这样的简单解决方案?解决这个问题的任何解决方案?

php codeigniter cache-control http-headers

1
推荐指数
1
解决办法
4771
查看次数

http标头ajax范围总是提供完整的网站

我尝试使用Range-header在Greasemonkey脚本中发送请求.请求的网站有点长,我知道我实际需要哪些部分,所以我想,而不是要求整个网站下载我可以请求必要的500字节来加快速度.

但是,Range: bytes=0-500总是给我完整的网站.我也试过了Content-Range: bytes=0-500,但是不起作用,Content-Length:500由于安全问题,不允许再设置它.

那么,有谁知道,为什么会这样?我正在使用Greasemonkey脚本:

 GM_xmlhttpRequest({
    method: 'GET',
    url: "http://colonel-strawberry.deviantart.com/",
     headers: {"Range": "bytes=0-500"}, 
    onload: function (responseDetails) {
      console.log(responseDetails);
    },
    onerror: function(responseDetails) {
      console.log("err:"+responseDetails);
    }
});
Run Code Online (Sandbox Code Playgroud)

使用response-header:

Date: Mon, 05 Nov 2012 17:11:42 GMT
Content-Encoding: gzip
Transfer-Encoding: chunked
P3P: policyref="/w3c/p3p.xml", CP="NOI DSP COR CURa OUR STP"
Connection: Keep-Alive
Server: Apache
Vary: Accept-Encoding
Content-Type: text/html
Cache-Control: private
Keep-Alive: timeout=45
Run Code Online (Sandbox Code Playgroud)

javascript greasemonkey range http-headers

1
推荐指数
1
解决办法
953
查看次数

HttpGet添加标题

我正在创建一个httpClient,我想在我的HttpGet请求中添加某些标头
我当前的代码产生以下请求.

GET /folder/index.html HTTP/1.0
主机:localhost:4444
连接:Keep-Alive
User-Agent:Apache-HttpClient/4.2.1(java 1.5)

我想要的是在该请求中添加另一个标头(If-Modified-Since).
我该怎么做?
谢谢 :)

public String httpGet(String s) {
    String url = s;
    StringBuilder body = new StringBuilder();
    httpclient = new DefaultHttpClient(); // create new httpClient
    HttpGet httpGet = new HttpGet(url); // create new httpGet object



    try {
        response = httpclient.execute(httpGet); // execute httpGet
        StatusLine statusLine = response.getStatusLine();
        int statusCode = statusLine.getStatusCode();
        if (statusCode == HttpStatus.SC_OK) {
            // System.out.println(statusLine);
            body.append(statusLine + "\n");
            HttpEntity e = response.getEntity();
            String entity = EntityUtils.toString(e);
            body.append(entity); …
Run Code Online (Sandbox Code Playgroud)

java http httpclient http-headers

1
推荐指数
1
解决办法
2万
查看次数

从HttpWebRequest请求的网页中省略图像

我提取网页以便将数据提供给我的应用程序.但是,这些页面包含许多我根本不需要的图像.我只需要文本数据.我的问题是网络请求花费了不可接受的时间.我认为这些图片也是在网络请求期间获取的.有没有办法消除图像并只下载文本数据?

以下是我目前使用的代码.

        var httpWebRequest = HttpWebRequest.Create(url) as HttpWebRequest;
        httpWebRequest.Method = "GET";
        httpWebRequest.ProtocolVersion = HttpVersion.Version11;
        httpWebRequest.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate");
        httpWebRequest.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
        httpWebRequest.Proxy = null;
        httpWebRequest.KeepAlive = true;
        httpWebRequest.Accept = "text/html";

        string responseString = null;
        var httpWebResponse = httpWebRequest.GetResponse() as HttpWebResponse;

        using (var responseStream = httpWebResponse.GetResponseStream())
        {
            using (var streamReader = new StreamReader(responseStream))
            {
                responseString = streamReader.ReadToEnd();
            }
        }
Run Code Online (Sandbox Code Playgroud)

此外,欢迎任何其他优化建议.

.net c# httpwebrequest http-headers

1
推荐指数
1
解决办法
681
查看次数

如何从HTTP_ACCEPT_LANGUAGE订购字符串

可能重复:
HTTP_ACCEPT_LANGUAGE

我尝试编写语言选项工具。为此我用

$default_language = (strtolower($_SERVER["HTTP_ACCEPT_LANGUAGE"]));

if (eregi('af', $default_language)) {do something}
Run Code Online (Sandbox Code Playgroud)

现在我想在回显时订购字符串:

$_SERVER["HTTP_ACCEPT_LANGUAGE"]
Run Code Online (Sandbox Code Playgroud)

例如,用户指定了多种语言。

带有不同语言的Chrome示例:

 nl,en-gb;q=0.8,en;q=0.6,fr;q=0.4,fr-ca;q=0.2
Run Code Online (Sandbox Code Playgroud)

因此,我如何读出字符串以一定的顺序显示它,nl这是我首选的第一语言。

该代码应类似于:

if ('nl'== array[0]) {do something}
Run Code Online (Sandbox Code Playgroud)

因此,如果有人可以帮助我,我将不胜感激。

非常感谢。

html php arrays string http-headers

1
推荐指数
1
解决办法
2588
查看次数