我正在发出 GET 请求来获取 JSON,它在任何设备上的任何浏览器中都可以正常工作,但不能通过 python 请求:
url = 'https://angel.co/autocomplete/new_tags'
params = {'query': 'sci', 'tag_type': 'MarketTag'}
resp = requests.get(url,params=params)
resp.raise_for_status()
Run Code Online (Sandbox Code Playgroud)
给出HTTPError: 403 Client Error: Forbidden for url: https://angel.co/autocomplete/new_tags?query=ab&tag_type=MarketTag
所以我尝试:
Request Headersfirefox 的 JSON 响应部分中找到的所有其他标头,但仍然是 403!可能的原因是什么?还有其他我可以尝试使用的东西吗?
编辑:我在headers属性中使用的请求标头(在 firefox 中检查 JSON 的标头部分):
{'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'en-US,en;q=0.5',
'Connection': 'keep-alive',
'Host': 'angel.co',
'If-None-Match: 'W/"5857a9eac987138be074e7bdd4537df8"',
'TE': 'Trailers', …Run Code Online (Sandbox Code Playgroud) python get http-headers http-status-code-403 python-requests
X-foo: bar当我从后端向 Apache发送标头并使用以下命令配置 Apache 时:
Header setifempty X-foo "baz"
Run Code Online (Sandbox Code Playgroud)
我收到两个X-foo headers而不是一个具有“baz”值的。
我使用版本 2.4.41 httpd(docker 镜像)。
这是错误还是配置错误?
我有简单的 vuejs 应用程序。在 main.js 中我有类似的内容:
import Vue from "vue";
import App from "./App.vue";
import router from "./router/routes";
import store from "./store/root";
import vuetify from "./plugins/vuetify";
import { RootActions } from "./constants";
import axios from "axios";
axios.get("https://api.github.com/users/mzabriskie").then(function(response) {
console.log({ headers: response.headers });
});
Run Code Online (Sandbox Code Playgroud)
在 chrome 控制台日志中我得到了这些:
然而,在https://runkit.com/greenlaw110/5e92363de9be35001ab0481e中,使用完全相同的代码,我打印出了更多的标题:
问题:
Authorization响应的标头,这真的可行吗?(注意我已经放入Authorization了Access-Control-Expose-Headers对预检请求的响应参考:
我正在使用 C#,我需要测试接受 System.Net.Http.Headers.HttpRequestHeaders 作为参数的方法之一。我们使用 FakeItEasy 进行测试。
但似乎 HttpResponseHeaders - 没有构造器(并且它是密封的),并且它使用 HttpHeader 作为基础。HttpHeader - 有构造函数,但 Header 属性只允许 get。
有没有办法构建虚拟/假的 HttpResponseHeaders 或 HttpResponseMessage 并在其中预设所需的标头值?
我有一个 CSP,其中包含以下行:
script-src 'nonce-{random}' 'unsafe-inline' 'unsafe-eval' 'strict-dynamic' https: http: https://static.cloudflareinsights.com https://mydomain.app/cdn-cgi/scripts/6c4dd986/cloudflare-static/email-decode.min.js;
Run Code Online (Sandbox Code Playgroud)
我可以看到页面响应标头中的 CSP 是正确的。
我仍然收到[Report Only] Refused to load the script https://mydomain.app/cdn-cgi/scripts/6c4dd986/cloudflare-static/email-decode.min.js错误。
Cloudflare 会自动注入此脚本标记,因此我不能依赖该strict-dynamic属性来覆盖它,也不能添加随机数。
这是因为scrict-dynamic覆盖 CSP 中的固定 url 而失败吗?我们需要在应用程序内严格动态,但我们还需要在这些情况下允许自定义白名单 URL。
有任何想法吗?
编辑:具体来说,我认为问题出在 cloudflare 上。如何允许 cloudflare 注入脚本,同时具有严格的动态设置?你不能给 cloudflare 一个随机数,而且 strict-dynamic 也不会让你加入白名单,那么如何克服这个问题呢?
重构我的应用程序以使用新的价格 API,但出现以下错误:
EventSource 的响应具有 MIME 类型(“application/json”),而不是“text/event-stream”。正在中止连接。
http://docs.nomics.com/#tag/Currency的免费 API 文档/currencies/ticker
这是我添加后的代码'Content-type': 'text/event-stream'
const headers: IHeaders = {
baseURL: NOMICS_API_BASE_URL, // 'https://api.nomics.com/v1/'
headers: {
'Content-Type': 'text/event-stream'
},
params: {
key: NOMICS_KEY
}
}
// * GET Currencies
export const getCurrenciesRequest = async () => {
console.log('getCurrenciesRequest...')
const nomics = axios.create(headers)
try {
const currencies = await nomics.get(`currencies/ticker&ids=BTC,ETH,XRP&interval=1d,30d&convert=USD`)
console.log('currencies', currencies)
return currencies
} catch (err) {
return err
}
}
Run Code Online (Sandbox Code Playgroud)
也刚刚尝试过
const currencies = await axios.get(`https://api.nomics.com/v1/currencies/ticker?key=demo-26240835858194712a4f8cc0dc635c7a&ids=BTC,ETH,XRP&interval=1d,30d&convert=USD`)
Run Code Online (Sandbox Code Playgroud)
和小写键
'content-type': 'text/event-stream'
不知道我错过了什么,希望能在这里得到一些想法...... …
我会在Python中使用flask做这样的事情:
@app.route('/login/', methods=['POST'])
def login():
token = request.headers["token"]
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚如何访问token标头并将其存储为String变量。
#![feature(proc_macro_hygiene, decl_macro)]
use rocket::{
config::{Config, Environment},
*,
};
fn main() {
let config = Config::build(Environment::Production)
.address("0.0.0.0")
.port(PORT)
.finalize()
.unwrap();
rocket::ignite().mount("/", routes![login]).launch();
}
#[post("/login")]
fn login() {
// Retrieve headers from request.
}
Run Code Online (Sandbox Code Playgroud) 大家好。
我遇到了下一个问题。我正在尝试执行 POST 请求,但是当我使用 Visual Studio Code 的调试器编译并执行它时,出现 400 Bad Request 错误。不管怎样,当我在 Postman 中执行相同的 POST 请求时,我收到了一个 200 OK 状态请求,其中包含继续我正在处理的下一部分所需的所有值。

此外,请求中有一个基本身份验证,在本例中我将其包含在 Postman 中并且工作正常。另一方面,在我的 C# 脚本中,我像这样执行它:
*这是我的模型,其中包含我的所有数据,用于将对象序列化为 JSON。
public class patient{
public string deviceId { get; set; }
public string deviceType { get; set; }
public string apiVersion { get; set; }
public string language { get; set; }
public externUserClass externUser{ get;set; }
public class externUserClass{
public externUserClass(string partnerExternalId, string username, string newPassword, string gender){
this.partnerExternalId = partnerExternalId;
this.username = username; …Run Code Online (Sandbox Code Playgroud) 我希望能够envoy在我的服务网格上捕获(记录)(至少部分)的 HTTP 标头istio。
我已经浏览了envoy's docs,并且在日志级别'部分中,它没有提到任何特定于标头的信息。
目前,我的istio-proxy日志是这样的(这是来自输出stern):
mysvc-69c46fbc75-d9v8j istio-proxy {"bytes_sent":"124","upstream_cluster":"inbound|80|http|mysvc.default.svc.cluster.local","downstream_remote_address":"10.11.11.1:0","authority":"some.url.com","path":"/health?source=dd_cluster_agent","protocol":"HTTP/1.1","upstream_service_time":"1","upstream_local_address":"127.0.0.1:40406","duration":"2","upstream_transport_failure_reason":"-","route_name":"default","downstream_local_address":"10.11.32.32:20000","user_agent":"Datadog Agent/7.24.0","response_code":"200","response_flags":"-","start_time":"2021-01-17T18:54:57.449Z","method":"GET","request_id":"61ae63c7-aa10-911b-9562-939kdhd49ddhj","upstream_host":"127.0.0.1:20000","x_forwarded_for":"10.16.32.1","requested_server_name":"outbound_.80_.mysvc_.faros.default.svc.cluster.local","bytes_received":"0","istio_policy_status":"-"}
Run Code Online (Sandbox Code Playgroud)
有没有办法记录http标题?(最好是其中一些,以控制伐木成本)
edit1按照评论中的建议,我检查了我的istio-operator资源,我发现访问日志记录似乎已启用
meshConfig:
accessLogEncoding: JSON
accessLogFile: /dev/stdout
Run Code Online (Sandbox Code Playgroud)
edit2我也尝试过以下操作:
curl -i -H "Custom-Header: application/json" https://my.url.net
Run Code Online (Sandbox Code Playgroud)
但在日志中istio-ingressgateway我没有看到我的自定义标头
istio-ingressgateway-58f69d8696-rmpwn istio-proxy {"user_agent":"curl/7.64.1","response_code":"200","response_flags":"-","start_time":"2021-01-18T19:02:48.645Z","method":"GET","request_id":"8e32c93c-484d-9c56-9489-8c5392793d97","upstream_host":"10.16.32.55:20000","x_forwarded_for":"10.16.32.1","requested_server_name":"my.url.net","bytes_received":"0","istio_policy_status":"-","bytes_sent":"124","upstream_cluster":"outbound|80||mysvc.default.svc.cluster.local","downstream_remote_address":"10.16.32.1:52804","authority":"my.url.net","path":"/","protocol":"HTTP/2","upstream_service_time":"9","upstream_local_address":"10.16.32.17:49826","duration":"10","upstream_transport_failure_reason":"-","route_name":"-","downstream_local_address":"10.16.32.17:8443"}
Run Code Online (Sandbox Code Playgroud) 我在 Go 中设置了一个非常基本的服务器
fs := http.FileServer(http.Dir("./public"))
http.Handle("/",fs)
Run Code Online (Sandbox Code Playgroud)
但问题是:我希望人们使用fetch(). 然而,由于设置了 CORS,这是不可能的。
Access to fetch 'xxxxx' from origin 'null' has
been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested
resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch
the resource with CORS disabled.
Run Code Online (Sandbox Code Playgroud)
我需要找到一种方法来传入标头Access-Control-Allow-Origin:*,但我不知道如何使用http.Handleor http.FileServer, only http.HandleFunc。
我无法使用,http.HandleFunc因为据我所知,它不允许我提供文件,而且我宁愿不使用文件处理系统自己获取文件(我可能必须将其作为最后的手段,除非有另一个方法)方式)。另外,它的效率很低。为什么要重新发明轮子,尤其是当这个轮子比我能想出的更好的时候?
有什么方法可以发送标头吗http.Handle()?
我对 Go 还很陌生,我已经有一段时间没有做过静态类型语言了,也没有做过处理传入 URL 的语言(我主要使用 PHP,所以......),所以我可能有也可能没有一个好的对概念的把握。
http-headers ×10
axios ×2
c# ×2
.net ×1
apache ×1
envoyproxy ×1
fakeiteasy ×1
get ×1
go ×1
istio ×1
javascript ×1
kubernetes ×1
logging ×1
nginx ×1
post ×1
postman ×1
python ×1
reactjs ×1
rust ×1
rust-rocket ×1
security ×1
unit-testing ×1
vue.js ×1
vuejs2 ×1