Make sure the url string that you pass to HttpPost
begins with http://
EDIT: I was able to perform a request with below code sample (notice the http
prefix)
private void httpStuff() {
new AsyncTask<Void, Void, String>() {
@Override
protected String doInBackground(Void... params) {
BufferedReader reader = null;
try {
String url = "http://www.offerpunch.com/parser/index.php/deals?SR=1&cat_id=&SRcat_id=&SRkeyword=hddhh&deal_city=&deal_area=";
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
InputStream is = httpEntity.getContent();
reader = new BufferedReader(new InputStreamReader(is));
StringBuilder total = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
total.append(line);
}
return total.toString();
} catch (ClientProtocolException ex) {
Log.e("LOG_TAG", null, ex);
} catch (IOException ex) {
Log.e("LOG_TAG", null, ex);
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException ex) {
}
}
}
return null;
}
protected void onPostExecute(String result) {
if (result == null) {
Log.d("LOG_TAG", "Result is null");
} else {
Log.d("LOG_TAG", "Result size: " + result.length());
Log.d("LOG_TAG", result);
}
};
}.execute();
}
The result is a huge string (~900k length), I am not even sure the user can actually understand the parsed data ... but that's off-topic.
In your case, I believe you either put the Internet
permission in a wrong place as noted here, or you're running the app on a crappy emulator, or you simply don't have connectivity on the device that you're running the app.
One more thing: that NullPointerException
that you get is because you assume the result is correct from server side. Make sure you have not-null checks before parsing ...