Hi,
I am able to get data using the following code:
private InputStream OpenHttpConnection(String urlString)
throws IOException
{
InputStream in = null;
int response = -1;
URL url = new URL(urlString);
URLConnection conn = url.openConnection();
if (!(conn instanceof HttpURLConnection))
throw new IOException("Not an HTTP connection");
try{
HttpURLConnection httpConn = (HttpURLConnection) conn;
httpConn.setAllowUserInteraction(false);
httpConn.setInstanceFollowRedirects(true);
httpConn.setRequestMethod("GET");
httpConn.connect();
response = httpConn.getResponseCode();
if (response == HttpURLConnection.HTTP_OK) {
in = httpConn.getInputStream();
}
}
catch (Exception ex)
{
throw new IOException("Error connecting");
}
return in;
}
but I am not able to post data and then get response. I have found a piece to post the data but I am not able to extract the response send by the server.
HttpClient httpClient = new DefaultHttpClient();
HttpPost postMethod = new HttpPost(mUrl);
try {
// prepare parameters
HttpParams params = new BasicHttpParams();
params.setParameter("locationJSON", mLocationJSON.toString());
postMethod.setParams(params);
HttpResponse response =httpClient.execute(postMethod);
Please help me.
manish wrote:Hi,
I want to post some data on the server and get response. Please share some example of this.