我想为http请求设置标头.标题名称是"日期"
http_request.setRequestHeader("Date", headers.date);
Run Code Online (Sandbox Code Playgroud)
但是,当我看到萤火虫发出请求时.我没有看到请求标题日期.
我该怎么设置?
我正在尝试使用带有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
由于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.谢谢你的帮助.
关于一切都在标题中.
我需要使用HTTP/1.0与服务器通信
我没有找到在xhr.setRequestHeader()中执行此操作的属性或选项
有什么想法吗?
谢谢你们 !
我已经设置了面向公众的网站,其标题为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:*只是为了不安全.
如果快递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...)
我正在尝试下载.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) 我正在努力理解http://www.w3.org/Protocols/rfc2616/rfc2616-sec2.html#sec2.2
如果连续行以空格或水平制表符开头,则HTTP/1.1标题字段值可以折叠到多行上.所有线性空白区域(包括折叠)都具有与SP相同的语义.在解释字段值或向下游转发消息之前,接收方可以用单个SP替换任何线性空白区域.
Run Code Online (Sandbox Code Playgroud)LWS = [CRLF] 1*( SP | HT )
我可以放任意数量<CR><LF><SP>,而不在线上放任何标题值吗?即这是有效的:Header:<CR><LF><SP><CR><LF><SP>Value
我已经开发了一个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) http-headers ×10
.net ×2
asp.net ×2
javascript ×2
ajax ×1
c# ×1
caching ×1
content-type ×1
cors ×1
date ×1
django ×1
express ×1
http ×1
http-1.0 ×1
http-post ×1
httphandler ×1
iis-6 ×1
json ×1
node.js ×1
php ×1
scala ×1
servicestack ×1
spray ×1
swagger ×1