[英]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.