Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Use HttpComponents <a href="http://hc.apache.org/" rel="nofollow noreferrer">http://hc.apache.org/</a>. You need:</p> <ul> <li>HttpComponents Core, <a href="http://mirrors.hostingromania.ro/apache.org/httpcomponents/httpcore/binary/httpcomponents-core-4.0.1-bin.zip" rel="nofollow noreferrer">direct download</a></li> <li>HttpComponents Client, <a href="http://mirrors.hostingromania.ro/apache.org/httpcomponents/httpclient/binary/httpcomponents-client-4.0-beta2-bin.zip" rel="nofollow noreferrer">direct download</a></li> <li>Commons Logging</li> </ul> <p>Example code:</p> <pre><code>import org.apache.http.message.BasicNameValuePair; import org.apache.http.NameValuePair; import org.apache.http.HttpResponse; import org.apache.http.HttpEntity; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.HttpClient; import java.util.ArrayList; import java.util.List; import java.io.OutputStream; import java.io.ByteArrayOutputStream; public class HttpClientTest { public static void main(String[] args) throws Exception { // request parameters List&lt;NameValuePair&gt; formparams = new ArrayList&lt;NameValuePair&gt;(); formparams.add(new BasicNameValuePair("q", "quality")); UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8"); HttpPost httppost = new HttpPost("http://stackoverflow.com/search"); httppost.setEntity(entity); // execute the request HttpClient httpclient = new DefaultHttpClient(); HttpResponse response = httpclient.execute(httppost); // display the response status code System.out.println(response.getStatusLine().getStatusCode()); // display the response body HttpEntity responseEntity = response.getEntity(); OutputStream out = new ByteArrayOutputStream(); responseEntity.writeTo(out); System.out.println(out); } } </code></pre> <p>Save it to HttpClientTest.java. Have this java file, httpcore-4.0.1.jar and httpclient-4.0-alpha4.jar in the same directory Supposing you have the sun java 1.6 jdk installed, compile it:</p> <pre><code>javac HttpClientTest.java -cp httpcore-4.0.1.jar;httpclient-4.0-alpha4.jar;commons-logging-1.1.1.jar </code></pre> <p>Execute it</p> <pre><code>java HttpClientTest.class -cp httpcore-4.0.1.jar;httpclient-4.0-alpha4.jar;commons-logging-1.1.1.jar </code></pre> <p>I would argue that is as simple in java as it is in php or python (your examples). In all cases you need:</p> <ul> <li>the sdk configured</li> <li>a library (with dependencies)</li> <li>sample code</li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload