gpt4 book ai didi

java - 带有负载的 Http 出站网关发布

转载 作者:行者123 更新时间:2023-11-30 02:11:05 25 4
gpt4 key购买 nike

我正在使用集成流发送 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);
}

这应该会让您了解可以发送到 requestChannelpayload类型。

关于java - 带有负载的 Http 出站网关发布,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50108253/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com