The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!
public void getData(){
class GetDataJSON extends AsyncTask<String, Void, String>{
@Override
protected String doInBackground(String... params) {
DefaultHttpClient httpclient = new DefaultHttpClient(new BasicHttpParams());
HttpPost httppost = new HttpPost("http://hollyannjones.joneschris.info/get-data.php");
// Depends on your web service
httppost.setHeader("Content-type", "application/json");
InputStream inputStream = null;
String result = null;
try {
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
inputStream = entity.getContent();
// json is UTF-8 by default
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null)
{
sb.append(line + "\n");
}
result = sb.toString();
} catch (Exception e) {
// Oops
}
finally {
try{if(inputStream != null)inputStream.close();}catch(Exception squish){}
}
return result;
}
public void getData()
{
class GetDataJSON extends AsyncTask<String, Void, String>{
@Override protected String doInBackground(String... params)
{
//DefaultHttpClient httpclient = new DefaultHttpClient(new BasicHttpParams());
// HttpPost httppost = new HttpPost("http://hollyannjones.joneschris.info/get-data.php");
// Depends on your web service
//httppost.setHeader("Content-type", "application/json");
String endpoint = String.format("http://hollyannjones.joneschris.info/get-data.php");
InputStream inputStream = null;
String result = null;
try
{
URL url = new URL(endpoint);
URLConnection conn = url.openConnection();
InputStream input = conn.getInputStream();
//HttpResponse response = httpclient.execute(httppost);
//HttpEntity entity = response.getEntity();
// inputStream = entity.getContent();
// json is UTF-8 by default
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null)
{
sb.append(line + "\n");
}
result = sb.toString();
}
catch (Exception e)
{
// Oops
}
finally
{
try{if(inputStream != null)inputStream.close();}catch(Exception squish){}
}
return result;
}
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Join the community of 500,000 technology professionals and ask your questions.