我正在尝试从json post请求获取标头内容.但我似乎无法在requesthandler中找到它的方法...
print_r($this->request);
没有显示任何有用的东西.我试过了
$this->request['head'];
$this->request['header'];
$this->request->getHeaders;
Run Code Online (Sandbox Code Playgroud)
这些都不起作用
我想知道是否可以使用Python从http请求头获取客户端的IP地址?我正在做一个天气项目,如果我能显示他自己所在位置的天气信息那就太好了。
python http request-headers python-requests python-requests-html
我在 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) 我使用修改过的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) 我的服务器要求我们将包含设备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) 我试图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) 我正在尝试请求一个需要使用令牌进行身份验证的 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) ajax ×1
cakephp ×1
extjs ×1
fetch-api ×1
http ×1
http-caching ×1
http-headers ×1
http-post ×1
httprequest ×1
javascript ×1
proxy ×1
python ×1