简体   繁体   English

自定义 HTTP 请求标头

[英]Custom HTTP request header

I'm trying to send a custom header to my web application using Google Http Client library like this:我正在尝试使用Google Http 客户端库向我的 Web 应用程序发送自定义标头,如下所示:

    HttpRequest request = requestFactory.buildGetRequest(url);
    HttpHeaders headers = new HttpHeaders();
    headers.set("custom", "somevalue");
    request.setHeaders(headers);
    HttpResponse response = request.execute();

However, when I try to enumerate the headers received by my web application, the header I added in my Java client is not there, what could be missing?但是,当我尝试枚举 Web 应用程序接收到的标头时,我在 Java 客户端中添加的标头不存在,可能缺少什么?

Try using wireshark to inspect the traffic and see if it's actually getting sent.尝试使用wireshark检查流量,看看它是否真的被发送了。 That would tell you if the problem is on the client or server-side.这会告诉您问题出在客户端还是服务器端。

Tichodrama is right, both sides may require you to use the prefix X- for your custom header. Tichodrama 是对的,双方可能都要求您在自定义标题中使用前缀 X-。

您需要在您的密钥前加上 X- 例如 httpChannel.setRequestHeader("X-Key", "value")

怎么样: request.addHeader("custom", "somevalue")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 提取请求的自定义标头(Java HTTP) - Fetching a custom header of a request (Java HTTP) 使用 Z38008DD81C2F4D7985ECF6E0CE8AF1D1 将自定义 Http header 添加到 SOAP 请求 - Add custom Http header to SOAP request with Spring Boot 向 BlazeDS 和 AMF 发送的请求添加自定义 HTTP 标头 - Add Custom HTTP Header to Request sent by BlazeDS and AMF Spring Boot 中的自定义拦截器【添加 HTTP 请求头】 - Custom interceptor in Spring Boot [ADD HTTP REQUEST HEADER] POST请求时如何在HTTP标头中设置自定义变量 - How to set a custom variable in HTTP header while POSTing a request 将我的自定义 http 标头添加到 Spring RestTemplate 请求/扩展 RestTemplate - Add my custom http header to Spring RestTemplate request / extend RestTemplate 如何使用自定义注释从Spring MVC中的HTTP请求中获取请求标头值? - How to get request header value from http request in spring mvc using custom annotaion? 多部分请求和自定义标题 - Multipart Request and Custom Header AccessDecisionManager中的HTTP请求缺少标头 - HTTP request in AccessDecisionManager is missing a header 解析HTTP标头的请求行 - Parse request line of http header
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM