如何使用spring发送HTTP post请求

Bas*_*sit 9 spring

我需要什么配置才能通过spring发送HTTP post请求.我使用的是java应用程序,它不是一个Web项目.我可以使用spring发送HTTP post请求吗?我谷歌它,但几乎所有的例子都使用spring MVC.我可以使用spring发送HTTP post请求吗?

我在网上发现了这个豆子,但我不知道该怎么办.我使用的是spring3.2,这个帖子我认为是2008年...

<bean id="httpClient" class="org.springbyexample.httpclient.HttpClientTemplate">
    <property name="defaultUri">
        <value><![CDATA[http://localhost:8093/test]]></value>
    </property>
</bean>
Run Code Online (Sandbox Code Playgroud)


有什么建议?

Dha*_*ath 11

如果您使用的是Spring 3.0 +,最好RestTemplate用于发送Http请求.连接RestTemplate后,可以使用其中的不同方法发送不同类型的Http请求.


ger*_*tan 2

您不需要 Spring 来发出 HTTP 请求,请参阅此帖子:Using java.net.URLConnection to fire and handler HTTP requests

是的,您可以在非 Web 应用程序/命令行应用程序中使用 Spring。只需创建一个 ApplicationContext 实例(例如:ClassPathApplicationContext 以及注入的 beans xml 配置路径)


归档时间:

查看次数:

31889 次

最近记录:

6 年,5 月 前