作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用集成流发送 POST 请求。我想知道如何指定请求正文?
IntegrationFlow myFlow() {
return IntegrationFlows.from("requestChannel")
.handle(Http.outboundGateway(uri)
.httpMethod(HttpMethod.POST)
.expectedResponseType(String.class)
)
.handle("myAssembler", "myFonction")
.channel("responseChannel")
.get();
}
最佳答案
本例中的请求正文是根据请求消息payload
确定的:
private HttpEntity<?> generateHttpRequest(Message<?> message, HttpMethod httpMethod) {
Assert.notNull(message, "message must not be null");
return (this.extractPayload) ? this.createHttpEntityFromPayload(message, httpMethod)
: this.createHttpEntityFromMessage(message, httpMethod);
}
其中 createHttpEntityFromPayload()
是这样的:
private HttpEntity<?> createHttpEntityFromPayload(Message<?> message, HttpMethod httpMethod) {
Object payload = message.getPayload();
if (payload instanceof HttpEntity<?>) {
// payload is already an HttpEntity, just return it as-is
return (HttpEntity<?>) payload;
}
HttpHeaders httpHeaders = this.mapHeaders(message);
if (!shouldIncludeRequestBody(httpMethod)) {
return new HttpEntity<>(httpHeaders);
}
// otherwise, we are creating a request with a body and need to deal with the content-type header as well
if (httpHeaders.getContentType() == null) {
MediaType contentType = (payload instanceof String)
? resolveContentType((String) payload, this.charset)
: resolveContentType(payload);
httpHeaders.setContentType(contentType);
}
if (MediaType.APPLICATION_FORM_URLENCODED.equals(httpHeaders.getContentType()) ||
MediaType.MULTIPART_FORM_DATA.equals(httpHeaders.getContentType())) {
if (!(payload instanceof MultiValueMap)) {
payload = this.convertToMultiValueMap((Map<?, ?>) payload);
}
}
return new HttpEntity<>(payload, httpHeaders);
}
这应该会让您了解可以发送到 requestChannel
的payload
类型。
关于java - 带有负载的 Http 出站网关发布,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50108253/
前不久,哔哩哔哩(一般常称为 B 站)发布了一篇文章《2021.07.13 我们是这样崩的》,详细回顾了他们在 2021.07.13 晚上全站崩溃约 3 小时的至暗时刻,以及万分紧张的故障定位与恢复过
想象一下这种情况,周围有一些智能手机和计算机,它们的 WiFi 适配器(无线适配器)打开,但没有必要连接到网络。 有没有办法通过 Linux 机器查看 MAC 地址? 任何见解表示赞赏。 最佳答案 断
我无法创建新的 Window Station 来运行我的应用程序 int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) { wprintf(L"
在 Conda 环境中安装包后,我想对该包中的代码进行一些更改。 在哪里可以找到包含已安装包的 site-packages 目录? 我有 Anaconda Python 2.7 base 发行版,但找
今天去改了matplotlib的配置。搜索 matplotlibrc 发现我有两个: 查看site-packages 文件夹,我发现很多包的名称中都有波浪号: ~klearn 是 sklearn ,但
我是一名优秀的程序员,十分优秀!