标签: http-headers

在PHP中解析HTTP_RANGE标头

是否存在HTTP_RANGE在PHP中正确解析标头的方法?我想在重新发明轮子之前我会问这里.

我目前正在使用

preg_match('/bytes=(\d+)-(\d+)/', $_SERVER['HTTP_RANGE'], $matches);
Run Code Online (Sandbox Code Playgroud)

解析标题,但不包括标题的所有可能值,所以我想知道是否有一个功能或库可以做到这一点?

提前致谢.

php apache http range http-headers

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

PHP:格式错误的标题

有人可以解释这个PHP代码有什么问题吗?(PHP版本5.3.5)

<?php 
    header('Bad Request', true, 400);
    exit;
Run Code Online (Sandbox Code Playgroud)

我得到状态500而不是400.在apache错误日志中我得到

来自脚本的格式错误的标题 错误的标头=错误的请求:listener.php

我在这做错了什么?我误解了文档吗?

php bad-request http-headers

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

@在HTTPPost请求中转换为%40

我试图发送邮件请求到webservice ..当我在参数中添加特殊字符@它被转换为%40.i已检查服务器端..他们正在获得%40而不是@.谁能帮我??这是我的代码..

httpclient = new DefaultHttpClient();
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("Email", "abc@gmail.com"));


httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
 ResponseHandler<String> responseHandler = new BasicResponseHandler();
String response = httpclient.execute(httppost,responseHandler);
Run Code Online (Sandbox Code Playgroud)

我也尝试过这种方法来防止我的参数编码.

httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, HTTP.PLAIN_TEXT_TYPE));
Run Code Online (Sandbox Code Playgroud)

但它提出了不受支持的编码算法

请帮我解决这个问题.

java https android http http-headers

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

响应标头VS元标记

我可以在meta-tag或response-header中删除一些信息,比如编码和语言.
我的问题:SEO和旧浏览器的最佳方式(也许是两者兼而有之)?

元标记示例:<meta http-equiv ="Content-Type"content ="text/html; charset = utf-8">
(PHP)标题示例:header('Content-Type:text/html; charset = utf -8' );
什么更好?

html seo http-headers

9
推荐指数
2
解决办法
8096
查看次数

在"Location:"标头中使用协议相对URI

我在PHP手册中注明了以下内容:

HTTP/1.1需要绝对URI作为»Location:包括方案,主机名和绝对路径的参数,但某些客户端接受相对URI.

为了方便用户优先选择HTTPS无处不在的连接,我想改变我的PHP脚本中的标题:

header("Location: http://www.example.com/"); 至 header("Location: //www.example.com/");

我已经测试了上面的代码在我的firefox浏览器上工作,但我不确定这是否是可行的事情.或者我是否应该从$_SERVER变量中提取协议并将其放入.

php http http-headers protocol-relative

9
推荐指数
2
解决办法
2895
查看次数

在Content-Type中指定charset时,Jersey和@FormParam无法正常工作

看起来Jersey 2.0(使用servlet 3.1)charset在Content-Type标题中指定属性时无法解码参数.

例如,考虑以下端点:

@POST
@Path("/hello")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Produces(MediaType.APPLICATION_JSON)
public Response hello(@FormParam("name") String name) {
    System.out.println(name);
    return ok();
}
Run Code Online (Sandbox Code Playgroud)

这个卷曲请求有效:

curl -X POST -H "content-type: application/x-www-form-urlencoded" -d "name=tom" http://localhost:8080/sampleapp/hello
Run Code Online (Sandbox Code Playgroud)

下面的请求,而不是不工作,该name参数是null:

curl -X POST -H "content-type: application/x-www-form-urlencoded; charset=UTF-8" -d "name=tom" http://localhost:8080/sampleapp/hello
Run Code Online (Sandbox Code Playgroud)

我认为charset=UTF-8内容类型中的添加会破坏我的代码.

编辑:

我打开了官方机票以防这是一个错误:https://java.net/jira/browse/JERSEY-1978

java servlets jax-rs jersey http-headers

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

让S3始终在其响应中包含Vary标头

我在S3上设置了CORS标头,当浏览器发出CORS请求(即包含Origin标头)时,S3会将所有正确的标头添加到响应中,包括Vary标头.但是,如果请求不包含Origin标头,则响应不包括Vary标头,这使得中间缓存(例如CDN)可以自由缓存响应并在稍后的请求进入时提供响应,即使后来的请求添加了Origin头.

如何让S3始终返回Vary标题?

cdn amazon-s3 http-headers cors

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

如何在Header @ Postman中发送api密钥?

我试图在Header而不是Url中发送Api Key.

当我尝试使用api发送Key时,它的工作方式很好: -

http://api.mydomain.com?key=dsjfh

屏幕跟随: - 在此输入图像描述

是否可以将密钥作为标题发送?

我试过这样的东西,但是没有用.

api http-headers postman

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

为什么响应304没有Content-Type标头?

我一直在玩express.js试图返回简单的json对象,并注意到即使我明确设置了Content-Type标题,application/json它只在第一个响应时可见,当状态代码是200时.每个跟随304的响应都没有Content-Type标题.

我的代码示例:

app.get('/user', function (req, res) {
    res.set('Content-Type', 'application/json');

    res.send([
        { user: "john", email: "john@example.com"},
        { user: "marry", email: "marry@example.com"},
        { user: "dan", email: "dan@example.com"}
    ]);
});
Run Code Online (Sandbox Code Playgroud)

这是什么原因?

http http-headers express

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

在重定向之前设置Express响应标头

我正在实现一个站点登录,它接收一个电子邮件/密码组合,检索一个API令牌,然后将其返回给用户,以便在localStorage中存储(加密).

目前,在成功发布到POST时/login,应用程序会将用户重定向到索引页面,并将令牌作为查询附加,如此(如此处所示):

login.post('/', function(req, res) {
    ...checking password...

    Auth.getToken(user, function(err, token) {
        res.redirect('/?token=' + token);
    });
});
Run Code Online (Sandbox Code Playgroud)

这工作正常,但我希望尽可能保持我的URL清洁,并将令牌设置为标题:

login.post('/', function(req, res) {
    ...checking password...

    Auth.getToken(user, function(err, token) {
        res.set('x-access-token', token);
        console.log(res._headers);
            // --> {'x-powered-by': 'Express', 'x-access-token': <token>}
        res.redirect('/');
    });
});
Run Code Online (Sandbox Code Playgroud)

console.log-ing res._headers显示标头已按预期设置,但是当我req.headers将索引页面登录时,它没有显示:

{ host: 'localhost:3000',
  connection: 'keep-alive',
 'cache-control': 'max-age=0',
 accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
 'upgrade-insecure-requests': '1',
 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36',
 referer: 'http://localhost:3000/login',
 'accept-encoding': 'gzip, deflate, …
Run Code Online (Sandbox Code Playgroud)

routing http-headers node.js express

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