How to send HTTP POST request and receive response?

As Schnapple says your question seems very broad and is confusing to read and understand.

Here is some general code to send a HTTP POST and get a response from a server though that may be helpful.


public String postPage(String url, File data, boolean returnAddr) {

    ret = null;

    httpClient.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.RFC_2109);

    httpPost = new HttpPost(url);
    response = null;

    FileEntity tmp = null;       

    tmp = new FileEntity(data,"UTF-8");

    httpPost.setEntity(tmp);

    try {
        response = httpClient.execute(httpPost,localContext);
    } catch (ClientProtocolException e) {
        System.out.println("HTTPHelp : ClientProtocolException : "+e);
    } catch (IOException e) {
        System.out.println("HTTPHelp : IOException : "+e);
    } 
            ret = response.getStatusLine().toString();

            return ret;
}

Leave a Comment