I'm trying to make a simple http post using the apache http client, and I can't for the life of me get it to work. I'm basing this off of the example at: http://hc.apache.org/httpclient-3.x/apidocs/org/apache/commons/httpclient/HttpState.html . The reason I don't think it's a problem with my url, host, or port is because I got them all to work in regular html forms and also in telnet.
The error I get is:
org.apache.commons.httpclient.ProtocolException: The server somehost.something.com failed to respond with a valid HTTP response
Here is my code:
public InputStream trialPost() { PostMethod post = new PostMethod("https://somesite.com/example.php"); NameValuePair[] data = { new NameValuePair("parameter1", "blah"), new NameValuePair("parameter2", "blah") }; post.setRequestBody(data); HttpState hs = new HttpState(); HttpConnection hc = new HttpConnection("somehost.something.com", 443); InputStream in = null; try { hc.open(); post.execute(hs, hc); in = post.getResponseBodyAsStream(); hc.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } // handle response. return in; }
HEADERresponse. Are you sure you are even reaching the intended page?