标签: http-headers

如何为http请求设置"Date"标头

我想为http请求设置标头.标题名称是"日期"

http_request.setRequestHeader("Date", headers.date);
Run Code Online (Sandbox Code Playgroud)

但是,当我看到萤火虫发出请求时.我没有看到请求标题日期.

我该怎么设置?

javascript date xmlhttprequest http-headers

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

使用ServiceStack的Swagger UI传递标头

我正在尝试使用带有ParameterType ="header"的APIMember属性在我们的SS服务中添加标头.

除了没有添加到RequestContext的标头之外,一切似乎都在工作.希望它支持标题.如果是,那么如何以及如何在Get查询或路径中不允许该头属性?

我究竟做错了什么?

namespace Test
{
    [Api(Description = "MyTest")]
    [Route("/Test", Verbs="GET")]
    public class MyRequest
    {
        [ApiMember(
            Name = "SolutionName", 
            ParameterType = "query", 
            Description = "Test", 
            DataType = "string", 
            IsRequired = true)]
        public string SolutionName { get; set; }

        [ApiMember(
            Name = "Token", 
            ParameterType = "header", 
            DataType = "string", 
            IsRequired = true)]
        public string Token { get; set; }

    }

}
Run Code Online (Sandbox Code Playgroud)

帮助赞赏!

谢谢,Nac

.net c# http-headers servicestack swagger

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

从请求中提取Spray.io Content-Type?

由于Spray.io是在低级别定义内容类型,我如何简单地引用传入请求的内容类型?

这是一个图像是PUT的简短示例.

      put {
        entity(as[Array[Byte]]) { data =>
          complete{
            val guid = Image.getGuid(id)
            val fileExtension = // match a file extension to content-type here
            val key = "%s-%s.%s" format (id, guid, fileExtension )
            val o = new Image(key, contentType, data)
            Image.store(o)
            val m = Map("path" -> "/client/%s/img/%s.%s" format (id, guid, fileExtension))
            HttpResponse(OK, generate(m))
          }
        }
      }
Run Code Online (Sandbox Code Playgroud)

鉴于上面的代码,提取内容类型的简单方法是什么?我可以简单地使用它来模式匹配到合适的fileExtension.谢谢你的帮助.

content-type scala http-headers spray

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

Ajax:强制HTTP/1.0

关于一切都在标题中.

我需要使用HTTP/1.0与服务器通信

我没有找到在xhr.setRequestHeader()中执行此操作的属性或选项

有什么想法吗?

谢谢你们 !

ajax xmlhttprequest http-1.0 http-headers

5
推荐指数
0
解决办法
488
查看次数

访问控制允许原点限制

我已经设置了面向公众的网站,其标题为Access-Control-Allow-Origin:*,以便我们可以使用JSON和AJAX.但是,我真正想要做的是将其限制为仅限于某些服务器.请求应该只来自我们控制的几台服务器.我无法在不添加代码的情况下找到有用的东西(示例伪代码):

for each domain in myDomains
    addheader Access-Control-Allow-Origin: domain
next
Run Code Online (Sandbox Code Playgroud)

是否可以在HTTP标头选项卡下的IIS中添加多个"Access-Control-Allow-Origin"?我知道可以将它实际添加到IIS,但它有效吗?

例:

Access-Control-Allow-Origin: http://domain1
Access-Control-Allow-Origin: http://domain2
Access-Control-Allow-Origin: http://127.0.0.1 (use using home as IP example)
Run Code Online (Sandbox Code Playgroud)

使用Access-Control-Allow-Origin:*只是为了不安全.

asp.net iis-6 http-headers cors

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

Django用标题创建/发出POST请求

我想以编程方式使用自定义标头发出POST请求.我怎样才能做到这一点?

其实我正在努力做到这一点 ; 使用google shortener api.也许我误解了:/

提前谢谢你:)

django http-post http-headers google-url-shortener

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

如何通过假设默认内容类型来解析Express/NodeJ中缺少内容类型的HTTP请求?

如果快递bodyParser不会触发,如何在请求中访问POST数据?

var server = express();
server.use(express.bodyParser());
server.post('/api/v1', function(req, resp) {
  var body = req.body;
  //if request header does not contain 'Content-Type: application/json'
  //express bodyParser does not parse the body body is undefined
  var out = {
    'echo': body
  };
  resp.contentType('application/json');
  resp.send(200, JSON.stringify(out));
});
Run Code Online (Sandbox Code Playgroud)

注意:在ExpressJs中,3.x + req.body不能自动使用,需要bodyParser激活.

如果未设置内容类型标头,是否可以指定默认内容类型application/json并触发bodyParser?

否则是否可以使用这个明确的POST函数中的裸nodejs方式访问POST数据?

(例如req.on('data', function...)

javascript json http-headers node.js express

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

强制下载,来自php文件

我正在尝试下载.mp4文件.(约1.3GB大小).我正在使用以下内容:

<?php 
$path = "video.mp4";
header('Accept-Ranges: bytes');  // For download resume
header('Cache-Control: must-revalidate, post-check=0, pre-check=0' );
header('Content-Description: File Transfer' );
header('Content-Disposition: attachment; filename="'.basename( $path ).'"' );
header('Content-Length: ' . filesize($path));  // File size
header('Content-Transfer-Encoding: binary');  // For Gecko browsers mainly
header('Content-Type: application/octet-stream' );
header('Expires: 0' );
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($path)) . ' GMT');
header('Pragma: no-cache' );
ob_clean();
flush();
readfile($path);
Run Code Online (Sandbox Code Playgroud)

我打开我的php文件,firefox弹出"想要保存"菜单.尺寸看起来正确.我按"另存为",到我的桌面.最终下载的文件,以随机大小列出,大约400MB(330,463和440).

响应标题是:

Connection: Keep-Alive
Content-Disposition:    attachment; filename="//www.frederikspang.dk/elevgallavideo.mp4"
Content-Length: 1422778850
Content-Type:   video/mp4
Date:   Sun, 30 Jun 2013 …
Run Code Online (Sandbox Code Playgroud)

php http-headers force-download

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

是http头中允许的多个线性空格

我正在努力理解http://www.w3.org/Protocols/rfc2616/rfc2616-sec2.html#sec2.2

如果连续行以空格或水平制表符开头,则HTTP/1.1标题字段值可以折叠到多行上.所有线性空白区域(包括折叠)都具有与SP相同的语义.在解释字段值或向下游转发消息之前,接收方可以用单个SP替换任何线性空白区域.

   LWS            = [CRLF] 1*( SP | HT )
Run Code Online (Sandbox Code Playgroud)

我可以放任意数量<CR><LF><SP>,而不在线上放任何标题值吗?即这是有效的:Header:<CR><LF><SP><CR><LF><SP>Value

http web-standards http-headers

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

缓存由http处理程序提供的动态图像

我已经开发了一个http处理程序来动态地提供图像..

我对每张图片都有相应的最后修改日期.

所以我已经实现了http头缓存,如下所示:

public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "image/jpeg";

        DateTime lastModified = Convert.ToDateTime("2/1/2013 12:00:00 AM");

        string eTag = "test.JPG" + lastModified.ToString();

        // set cache info
        context.Response.Cache.VaryByHeaders["If-Modified-Since"] = true;
        context.Response.Cache.VaryByHeaders["If-None-Match"] = true;
        context.Response.Cache.SetLastModified(lastModified);
        context.Response.Cache.SetETag(eTag);

        //Set cache control header
        context.Response.Cache.SetCacheability(HttpCacheability.ServerAndPrivate);

        Byte[] imageBytes = CreateImage();
        context.Response.OutputStream.Write(imageBytes, 0, imageBytes.Length);
    }
Run Code Online (Sandbox Code Playgroud)

注意:这里 将为每个图像动态获取lastModified,每个图像的名称也不同.

响应标题

HTTP/1.1 200 OK
Cache-Control: private
Content-Type: image/jpeg
Last-Modified: Thu, 31 Jan 2013 18:30:00 GMT
Etag: test.JPG2/1/2013 12:00:00 AM
Vary: If-Modified-Since, If-None-Match
Server: Microsoft-IIS/8.0
X-AspNet-Version: 4.0.30319
X-SourceFiles: =?UTF-8?B?RTpcTGVhcm5pbmdcQ2FjaGVcR2V0SW1hZ2UuYXNoeA==?= …
Run Code Online (Sandbox Code Playgroud)

.net asp.net caching httphandler http-headers

5
推荐指数
0
解决办法
1051
查看次数