标签: http-headers

使用 nginx 反向代理时,nodejs 中未收到自定义标头

我有和的NodeJS Nginx的运行我是API“API_KEY”在增派头及其在没有收到req.headers并req.get('api_key')在我的NodeJS有nginx的波纹管配置文件

server {
    listen 80;
    listen [::]:80 default_server ipv6only=on;
    server_name mysite.com;
    return 301 https://$host$request_uri;
 location / {
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-NginX-Proxy true;
    proxy_pass http://localhost:9102/;
    proxy_set_header Host $http_host;
    proxy_set_header api_key $http_api_key; 
    #proxy_set_header api_key 'Some Value'; works 
    proxy_redirect off;
  }
}
Run Code Online (Sandbox Code Playgroud)

如果设置proxy_set_header api_key 'some value'它的值有效并且标题打印在控制台上但api_key会发生变化,这就是我使用的原因,$http_api_key以便api_key自定义标题中的任何内容在从其余客户端发送时被接收。我已经尝试了几个解决方案,proxy_set_header api_key $upstream_http_api_key;但没有帮助。我想接收从 nodejs 中的休息客户端发送的任何自定义标头。

reverse-proxy nginx http-headers node.js nginx-reverse-proxy

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

HTTP 内容类型标头中的字符集组件是必需的吗?

一个HTTP请求可能有这样的Content-Type标题:

GET / HTTP/1.1
...
Content-Type: text/xml; charset=utf-8
...
Run Code Online (Sandbox Code Playgroud)

是否存在该charset组件是强制性的情况?万一,什么时候?

可能的Content-Type标题示例,不一定正确:

Content-Type: text/xml
Content-Type: charset=utf-8
Content-Type: text/xml; charset=utf8
Content-Type:
Run Code Online (Sandbox Code Playgroud)

标准信息:

编辑注意:似乎这个参考已经过时了,RFC 7231 现在是正确的版本,正如@RobbyCornelissen 所建议的那样。

标准对此说得很少(或者我可能看错了地方):https : //www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

14.17 内容类型

Content-Type entity-header 字段指示发送给接收者的实体主体的媒体类型,或者在 HEAD 方法的情况下,如果请求是 GET,则将发送的媒体类型。

   Content-Type   = "Content-Type" ":" media-type
Run Code Online (Sandbox Code Playgroud)

媒体类型在第 3.7 节中定义。该领域的一个例子是

   Content-Type: text/html; charset=ISO-8859-4
Run Code Online (Sandbox Code Playgroud)

第 7.2.1 节提供了对识别实体媒体类型方法的进一步讨论。

http http-headers

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

从 Angular 中的 get Http 请求中获取标头

我正在调用一个获取 blob 数据的 API。

后端也向我发送标题中的文件名。

我的实际问题是我无法从 api 获取标题。

这是我的service.ts

public openFile(path) {
  let url='/download/';
  let pathFile= new HttpParams().set('pathFile', path);
  return this.httpClient.get(url,{params:pathFile, responseType: 'blob' });
Run Code Online (Sandbox Code Playgroud)

在component.ts 中,我调用了该服务。当我尝试打印时,res.headers我在控制台中未定义。

openFile(path){
  this.creditPoliciesService.openFile(path).toPromise().then (data => {
    console.log("dataaaaaa",data.headers); // undefined
    var blob = new Blob([data], {type: 'application/pdf'}); 
    if (window.navigator && window.navigator.msSaveOrOpenBlob) {
      window.navigator.msSaveOrOpenBlob(blob);
    }
    else {
      var fileURL = URL.createObjectURL(blob); 
      window.open(fileURL);
    }
  });
}
Run Code Online (Sandbox Code Playgroud)

在开发工具管理员中,我在响应标头中获得信息,但我无法在响应变量中找到它们。

httprequest http-headers typescript angular-services angular

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

不支持中文的 Content-Disposition 文件名

我一直在尝试下载带有中文文件名的附件,但不知何故他们的编码在下载时发生了变化,并且在有中文字符的地方保存了一些乱码文件名。

技术:Java 服务器:Apache Tomcat

这是我已经尝试过的

response.setHeader("Content-Disposition", "attachment; filename=\"7_6_4_AM__2017_JS_003_??????_B1_108\"");

输出(下载的附件名称):“7_6_4_AM__2017_JS_003_W_äð”

我还尝试在引用后将 * 附加到文件名指令:

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Disposition response.setHeader("Content-Disposition", "attachment; filename*=\"7_6_4_AM__2017_JS_003_??????_B1_108\"");

输出(下载的附件名称):“706.txt”

还,

在我的研究中,我发现 HTTP 标头消息不能携带 ISO-8859-1 字符集之外的字符。

https://tools.ietf.org/html/rfc5987

提前致谢。

java file httpresponse character-encoding http-headers

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

使用 Angular 5 发送自定义标头

我正在尝试从前端应用程序发送自定义 HTTP 标头,以便它与网关进行交互。这是我的角函数:

import {Http, Headers, Response, RequestOptions } from ‘@angular/http’;
getXById(id :number){
    let options = nee RequestOptions({ headers : new Headers({“X-fastgate-resource” :”resource_name}) });
    return this.http.get( http://url + “/resource”, options)
Run Code Online (Sandbox Code Playgroud)

我希望看到一个标题,“X-fastgate-resource”作为键,“resource_name”作为值。我得到的是这样的:

Request Headers:
   OPTIONS http://url HTTP/1.1
   host...
   Access-Control-Request-Headers: x-fastgate-resource 
Run Code Online (Sandbox Code Playgroud)

javascript http http-headers typescript angular5

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

如何使用 shell 脚本运行带有标头的 curl 命令

我试图运行一个 shell 脚本,其中包含一个 curl 命令,其所需的标题如下。

counter=1
H1='Content-Type: application/json'
H2='Accept: application/json'
H3='Authorization: Bearer a0a9bb26-bb7d-3645-9679-2cd72e2b4c57'
URL='http://localhost:8280/mbrnd_new/v1/post'

while [ $counter -le 10 ]

do

TEST="curl -X POST --header $H1 --header $H2 --header $H3 -d @s_100mb.xml $URL"
echo $TEST
RESPONSE=`$TEST`
echo $RESPONSE
sleep 5
done
echo "All done"
Run Code Online (Sandbox Code Playgroud)

它给出了一个错误

curl: (6) Could not resolve host: application
curl: (6) Could not resolve host: Bearer
curl: (6) Could not resolve host: a0a9bb26-bb7d-3645-9679-2cd72e2b4c57
<ams:fault xmlns:ams="http://wso2.org/apimanager/security"><ams:code>900902</ams:code><ams:message>Missing Credentials</ams:message><ams:description>Required OAuth credentials not provided. Make sure your API invocation call has …
Run Code Online (Sandbox Code Playgroud)

shell curl http-headers access-token

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

如何从 angular http 的响应中读取状态?

我在从响应中读取状态代码时遇到了一些问题。

我在服务中调用 api,

return this.http.get<string>( this.remoteServer + '/google.com/open', httpOptions);
Run Code Online (Sandbox Code Playgroud)

在我的控制器中,我有,

open() {
    this.openService.open(this.selected.qrCode)
    .subscribe(
      data => {
       console.log(data);
       this.toastService.showSuccess('Unlock Successfull', 'success');
      }
    );
  }
Run Code Online (Sandbox Code Playgroud)

现在我想阅读 http 状态文本,

我从上述调用中得到的示例 http 响应是。

HttpErrorResponse {headers: HttpHeaders, status: 200, statusText: "OK", url: " https://google.com/open ", ok: false, ...}

如何读取控制器中的状态文本。

请帮我

httpresponse http-headers angular angular-httpclient

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

如何使用 TBA 身份验证请求 Netsuite RESTlet

我正在尝试使用 Alamofire (SWIFT) 请求我的 Netsuite RESTlet,但我遇到了几个困难:在文档中,它指定了所需的不同参数(见下文)。

文件:

OAuth 1.0 RESTlet 授权标头需要下表中描述的数据。其中一些值可以从 NetSuite UI 获得。必须计算其他值。通常,您的集成应包括识别这些值并生成完成的标头的逻辑。按照 OAuth 1.0 协议创建授权标头。 在此处输入图片说明

但是在邮递员中,我使用了额外的参数(消费者秘密和令牌秘密),如果我删除它们,它就起作用了,它不起作用

在此处输入图片说明

当我检查邮递员生成的授权标头时,我只看到文档中的指定参数:

OAuth realm="my realm",oauth_consumer_key="myConsumerKey",oauth_token="myAccessToken",
oauth_signature_method="HMAC-SHA1",oauth_timestamp="1543488570",
oauth_nonce="ERxdLbUfkeh",oauth_version="1.0",oauth_signature="UeqmxAyeUqtPoICLo%2FARsQE8B1E%3D"
Run Code Online (Sandbox Code Playgroud)

如果有人可以向我解释这一点,我可以在我的应用程序中实现 TBA 身份验证,但现在我需要更好地理解这种身份验证。

oauth netsuite http-headers access-token

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

使用客户端为每个 HTTP 请求添加标头

我知道我可以使用手动向每个 HTTP 请求添加标头

cli := &http.Client{}
req, err := http.NewRequest("GET", "https://myhost", nil)
req.Header.Add("X-Test", "true")
if err != nil {
    panic(err)
}
rsp, err := cli.Do(req)
Run Code Online (Sandbox Code Playgroud)

但我想为我的应用程序中的每个 HTTP 请求自动添加此标头。

最好的方法是什么?

go http-headers go-http

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

如何使用 Apache 配置设置 SameSite cookie 属性?

我无法在“应用程序”选项卡中使用内置开发人员工具看到 SameSite=Strict。

我在 Apache 配置中添加了下面的标题代码

Header always edit Set-Cookie (.*) "$1;SameSite=Strict"
Header edit Set-Cookie ^(.*)$ $1;SameSite=Strict
Run Code Online (Sandbox Code Playgroud)

请让我知道如何使用上述设置设置 SameSite=Strict。

apache http-headers samesite

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