gpt4 book ai didi

java - 在camel路由中发送POST请求

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

我正在使用 Apache Camel 来实现 SOA 集成层。

但是当我尝试向外部 Web 服务发送 POST 请求时遇到一些问题。

这是我的 Camel 路线:

from("jetty:http://localhost:5000/plus_grand")
.setHeader(Exchange.HTTP_METHOD , constant("POST"))
.to("http://localhost/sub?bridgeEndpoint=false&throwExceptionOnFailure=false")

http://localhost/sub 是一个简单的 php 页面。本页打印请求信息。

代码是:

echo "<pre>";
print_r($_SERVER);
echo "</pre>";

当我尝试运行它时,我得到以下结果:

Array
(
[HTTP_HOST] => localhost
[HTTP_USER_AGENT] => Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:47.0) Gecko/20100101 Firefox/47.0
[HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
[HTTP_ACCEPT_LANGUAGE] => en-US,en;q=0.5
[HTTP_ACCEPT_ENCODING] => gzip, deflate
[HTTP_COOKIE] => csrftoken=rqcFAHftMkWsDEoLudTWIjPseAU7sJ40; oauth_consumer_key=136a3fd63028e1d157c6b939bcbe771c2dfe5710
[HTTP_CONNECTION] => keep-alive
[PATH] => /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
[SERVER_SIGNATURE] =>
Apache/2.4.7 (Ubuntu) Server at localhost Port 80


[SERVER_SOFTWARE] => Apache/2.4.7 (Ubuntu)
[SERVER_NAME] => localhost
[SERVER_ADDR] => 127.0.0.1
[SERVER_PORT] => 80
[REMOTE_ADDR] => 127.0.0.1
[DOCUMENT_ROOT] => /var/www/html
[REQUEST_SCHEME] => http
[CONTEXT_PREFIX] =>
[CONTEXT_DOCUMENT_ROOT] => /var/www/html
[SERVER_ADMIN] => webmaster@localhost
[SCRIPT_FILENAME] => /var/www/html/sub/index.php
[REMOTE_PORT] => 38604
[GATEWAY_INTERFACE] => CGI/1.1
[SERVER_PROTOCOL] => HTTP/1.1
[REQUEST_METHOD] => GET
[QUERY_STRING] =>
[REQUEST_URI] => /sub/
[SCRIPT_NAME] => /sub/index.php
[PHP_SELF] => /sub/index.php
[REQUEST_TIME_FLOAT] => 1480887502.957
[REQUEST_TIME] => 1480887502
)

可以看到,请求方法是GET

请问这是什么问题。

最佳答案

您的路由正在连接到基于 http v3.x 客户端库的旧版 http 组件。建议使用 http4://.. 作为端点。

然后使用每个示例的预定义常量:

from("direct:start")
.setHeader(Exchange.HTTP_METHOD,constant(org.apache.camel.component.http4.HttpMethods.POST))
.to("http4://www.google.com")

引用:http://camel.apache.org/http4.html

关于java - 在camel路由中发送POST请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40964528/

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