In below example the reasponse we are getting is written on sdcard file....For using below method the following jar files are required
httpmime-4.1.1.jar
String url = Constants.IP_ADDRESS+ "history.php?xml="+imei+"&dremail=" + email;
String filename = "history.txt";
String replaceUnderscore = url.replace(" ", "_");
//Call the method
httphit(replaceUnderscore, filename);
//Below is the httphit method
public int httphit(String http_url, String filepath) {
int result = 0;
BufferedReader bufferedReader = null;
try {
HttpClient httpclient = new DefaultHttpClient();
String UrlPost = http_url;// +IMEI_string;
HttpPost httppost = new HttpPost(UrlPost);
HttpResponse response = httpclient.execute(httppost);
if(filepath != "")
{
File file = new File("/sdcard/", filepath);
file.createNewFile();
FileOutputStream fileOutput = new FileOutputStream(file);
InputStream input = response.getEntity().getContent();
Log.e("Input MAP HTTPHIT",input.toString());
byte[] buffered = new byte[1024];
int bufferLength = 0;
while ((bufferLength = input.read(buffered)) > 0)
{
fileOutput.write(buffered, 0, bufferLength);
Log.e("Input MAP HTTPHIT While in",buffered.toString());
}
Log.e("Input MAP HTTPHIT While out",buffered.toString());
// close the output stream when done
fileOutput.flush();
fileOutput.close();
result = 1;
}
}
catch (IOException e) {
Log.e(e.getClass().getName(), e.getMessage());
}
return result;
}
httpmime-4.1.1.jar
String url = Constants.IP_ADDRESS+ "history.php?xml="+imei+"&dremail=" + email;
String filename = "history.txt";
String replaceUnderscore = url.replace(" ", "_");
//Call the method
httphit(replaceUnderscore, filename);
//Below is the httphit method
public int httphit(String http_url, String filepath) {
int result = 0;
BufferedReader bufferedReader = null;
try {
HttpClient httpclient = new DefaultHttpClient();
String UrlPost = http_url;// +IMEI_string;
HttpPost httppost = new HttpPost(UrlPost);
HttpResponse response = httpclient.execute(httppost);
if(filepath != "")
{
File file = new File("/sdcard/", filepath);
file.createNewFile();
FileOutputStream fileOutput = new FileOutputStream(file);
InputStream input = response.getEntity().getContent();
Log.e("Input MAP HTTPHIT",input.toString());
byte[] buffered = new byte[1024];
int bufferLength = 0;
while ((bufferLength = input.read(buffered)) > 0)
{
fileOutput.write(buffered, 0, bufferLength);
Log.e("Input MAP HTTPHIT While in",buffered.toString());
}
Log.e("Input MAP HTTPHIT While out",buffered.toString());
// close the output stream when done
fileOutput.flush();
fileOutput.close();
result = 1;
}
}
catch (IOException e) {
Log.e(e.getClass().getName(), e.getMessage());
}
return result;
}
No comments:
Post a Comment