标签: request-headers

Cakephp Rest获取标题

我正在尝试从json post请求获取标头内容.但我似乎无法在requesthandler中找到它的方法...

print_r($this->request); 没有显示任何有用的东西.我试过了

$this->request['head'];

$this->request['header'];

$this->request->getHeaders;
Run Code Online (Sandbox Code Playgroud)

这些都不起作用

cakephp httprequest request-headers requesthandler

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

是否可以从 HTTP 请求标头获取客户端的 IP 地址?

我想知道是否可以使用Python从http请求头获取客户端的IP地址?我正在做一个天气项目,如果我能显示他自己所在位置的天气信息那就太好了。

python http request-headers python-requests python-requests-html

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

浏览器缓存请求/响应,没有任何 Cache-Control 标头

我在 SPA Web 应用程序和 REST API 后端遇到浏览器缓存问题。我可以在打开开发人员工具的情况下在 Firefox 和 Safari 上重现它:我确保缓存未禁用。

当我进入第一个特定页面,该页面只是从 REST API 获取并显示对象时,我使用“硬刷新”(Mac 上的 CMD+R)来完成此操作。我看到以下标题:

第一个请求:

Host: localhost:5000
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:77.0) Gecko/20100101 Firefox/77.0
Accept: application/json, text/plain, */*
Accept-Language: en,it;q=0.7,fr;q=0.3
Accept-Encoding: gzip, deflate, br
Origin: http://localhost:3000
DNT: 1
Connection: keep-alive
Referer: http://localhost:3000/literature/sde5e-zeb98
Cookie: ...
If-Modified-Since: Fri, 10 Jul 2020 16:19:24 GMT
If-None-Match: "2"
Cache-Control: max-age=0
Run Code Online (Sandbox Code Playgroud)

(注意Cache-Control标题,由于硬刷新而自动添加)

回复:

HTTP/1.0 200 OK
Content-Type: application/json
Content-Length: 6128
ETag: "2"
Last-Modified: Fri, 10 Jul 2020 …
Run Code Online (Sandbox Code Playgroud)

http-caching request-headers http-headers

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

App Engine webapp.RequestHandler子实例在__init__期间没有self.request

我使用修改过的webapp.RequestHandler处理我的应用程序中的请求:

class MyRequestHandler(webapp.RequestHandler):
    """
    Request handler with some facilities like user.
    self.out is the dictionary to pass to templates 
    """
    def __init__(self, *args, **kwargs):
        super(MyRequestHandler, self).__init__(*args, **kwargs)
        self.out = {
            'user': users.get_current_user(),
            'logout_url': users.create_logout_url(self.request.uri)
            }

    def render(self, template_name):
        """
        Shortcut to render templates
        """
        self.response.out.write(template.render(template_name, self.out))


class DeviceList(MyRequestHandler):
    def get(self):
        self.out['devices'] = GPSDevice.all().fetch(1000)
        self.render('templates/device_list.html')
Run Code Online (Sandbox Code Playgroud)

但我得到一个例外:

line 28, in __init__
    self.out['logout_url'] = users.create_logout_url(self.request.uri)
AttributeError: 'DeviceList' object has no attribute 'request'
Run Code Online (Sandbox Code Playgroud)

当导致异常的代码移出__init__一切都很好时:

class MyRequestHandler(webapp.RequestHandler):
    """
    Request handler with some facilities …
Run Code Online (Sandbox Code Playgroud)

google-app-engine request-headers

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

在POST方法windows phone 7中为WebHeaderCollection添加标题

我的服务器要求我们将包含设备ID的标头发布到服务器,通常我们可以这样做:

        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(_connectionURL);
        request.ContentType = "application/x-www-form-urlencoded";

        request.Headers.Add    // THIS METHOD DOESN'T EXIST in windows phone 7
        request.Method = "POST";
Run Code Online (Sandbox Code Playgroud)

它有这个方法,它允许你设置可用的标题,但我想要的标题不包括在那里,我如何添加另一个标题到WebHeaderCollection.

request.Headers.AllKeys.SetValue //this function to set the available headers.
Run Code Online (Sandbox Code Playgroud)

http-post request-headers windows-phone-7

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

extjs store.load传递授权标头没有流入

我试图Authorization: 'Bearer <TOKEN>'通过参数传入标题到我的store.load(),它不起作用.

如果我这样做,它的工作原理如下:

Ext.define('ExtApplication4.model.MenuListModel', {
    extend: 'ExtApplication4.model.Base',
    requires: [
        'ExtApplication4.model.Base'
    ],
    fields: [
        {
            name: 'text',
            type: 'string'
        },
        {
            name: 'iconCls',
            type: 'string'
        },
        {
            name: 'className',
            type: 'string'
        }
    ],
    proxy: {
        type: 'ajax',
        url: 'http://xxxxx/xxx/api/user/getusermenus/',
        reader: {
            type: 'json',
            rootProperty: 'data'
        },
        headers: {
            Authorization: 'Bearer ' + Ext.decode(Ext.util.Cookies.get('token'))
        }
    }
});
Run Code Online (Sandbox Code Playgroud)

问题是我想填充我的授权标题store.load().我花了好几个小时试图找到这样做的语法.我尝试标题的所有内容都没有添加.

有人能告诉我怎么做吗?

这是我试过的:

targetStore.load({
    params: {
        username: uname
    },
    //headers: {            
    //    Authorization: 'Bearer ' + token;
    //}, …
Run Code Online (Sandbox Code Playgroud)

ajax proxy extjs request-headers

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

为什么我不能在 Request 对象上设置一些标头?

我正在尝试请求一个需要使用令牌进行身份验证的 REST API。构造 Request 对象时,一些标头会消失。为什么我无法设置授权标头?

let http_headers = {
        "Content-type": "application/json",
        'Authorization': 'Token token='+my_token,
        'Accept': 'Application/json'
    };

let url = this.base_url + '/api/v1/test';
let init =  {
            method: "POST",
            headers: new Headers(http_headers),
            mode: 'no-cors',
            credentials: 'omit' // I try that, but it doesn't seem to have effect
        };
let req = new Request( url, init );
console.log(req.headers.get("Accept")); // Application/json
console.log(req.headers.get("Authorization")); // null, why ?
Run Code Online (Sandbox Code Playgroud)

javascript request-headers fetch-api

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