CXF WebClient 覆盖 HTTP 内容类型
我正在尝试充当第三方 Web 服务的代理,并且需要转换 REST 请求。我遇到的一个问题是,无论我做什么,Content-Type 标头似乎都会被覆盖。代码其实很简单(context就是一个@Context MessageContext 变量):.
WebClient client = WebClient.create(url)
.header("real-header-removed", "auth-string-removed")
//.header("Content-Type", context.getHttpHeaders().getMediaType().toString());
.type(context.getHttpHeaders().getMediaType());
Response resp = client.get();
return (InputStream)resp.getEntity();
header 和 .type 都不起作用。请求的 tcpmon 输出是:
Content-Type: */*
real-header-removed: auth-string-removed
Accept: application/xml
User-Agent: Apache CXF 2.3.5
Cache-Control: no-cache
Pragma: no-cache
如何避免 Content-Type 覆盖(或者更确切地说,为什么会这样 发生?)
I'm trying to act as a proxy to a third party webservice, and need to transform a REST request. One issue that I have is that the Content-Type header seems to get overridden no matter what I do. The code is actually very simple (context is an @Context MessageContext
variable):
WebClient client = WebClient.create(url)
.header("real-header-removed", "auth-string-removed")
//.header("Content-Type", context.getHttpHeaders().getMediaType().toString());
.type(context.getHttpHeaders().getMediaType());
Response resp = client.get();
return (InputStream)resp.getEntity();
Neither the .header nor the .type worked. The tcpmon output of the request is:
Content-Type: */*
real-header-removed: auth-string-removed
Accept: application/xml
User-Agent: Apache CXF 2.3.5
Cache-Control: no-cache
Pragma: no-cache
How do I avoid the Content-Type override (or rather, why is it
happening?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我需要使用 client.invoke("GET", "");
I needed to use client.invoke("GET", "");