Skip to content Skip to sidebar Skip to footer

Get Response After Posting To Server

To post data to the server, I use the following method, successfully posts to the server, here I need to get one number that is registration id. I have coded that in the server php

Solution 1:

try this snippets, i will work to you,

URL url;
url = new URL("http://www.url.com/app.php");
URLConnection connection;
connection = url.openConnection();
HttpURLConnection httppost = (HttpURLConnection) connection;
httppost.setDoInput(true);
httppost.setDoOutput(true);
httppost.setRequestMethod("POST");
httppost.setRequestProperty("User-Agent", "Tranz-Version-t1.914");
httppost.setRequestProperty("Accept_Language", "en-US");
httppost.setRequestProperty("Content-Type",
        "application/x-www-form-urlencoded");
DataOutputStream dos = new DataOutputStream(httppost.getOutputStream());
dos.write(b); // bytes[] b of post data

String reply;
InputStream in = httppost.getInputStream();
StringBuffer sb = new StringBuffer();
try {
    int chr;
    while ((chr = in.read()) != -1) {
        sb.append((char) chr);
    }
    reply = sb.toString();
} finally {
    in.close();
}

Post a Comment for "Get Response After Posting To Server"