13

What configuration do i need to send HTTP post request through spring. I am using java application , it's not a web project. Can i use spring to send HTTP post request? I google it but most almost all examples are using spring MVC. Can i use just spring to send HTTP post request ?

I found this bean on net but I don't know what to do after it. I am using spring3.2 and this post i think is of year 2008...

<bean id="httpClient" class="org.springbyexample.httpclient.HttpClientTemplate">
    <property name="defaultUri">
        <value><![CDATA[http://localhost:8093/test]]></value>
    </property>
</bean>


Any suggestions?

3
  • try using jersy jersey.java.net Commented Jul 2, 2013 at 11:04
  • if Spring is not obligatory, than use Apache HTTP client Commented Jul 2, 2013 at 11:04
  • your solution is REST or SOAP api Commented Jul 2, 2013 at 11:14

2 Answers 2

12

If you are using Spring 3.0+, it will be better to use RestTemplate for sending HTTP requests. Once you wire the RestTemplate (API), you can use different methods in it to send different types of HTTP requests.

Sign up to request clarification or add additional context in comments.

Comments

2

You don't need Spring just to issue a HTTP post, see this post: Using java.net.URLConnection to fire and handle HTTP requests

And yes you can use Spring in a non-web application / command line application. Just create an instance of ApplicationContext (eg: ClassPathApplicationContext with path to your beans xml configuration injected)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.