01.
public
class
HttpTask
extends
AsyncTask<String, Void, JSONObject> {
02.
03.
@Override
04.
protected
JSONObject doInBackground(String... urls) {
05.
06.
try
{
07.
HttpClient httpclient =
new
DefaultHttpClient();
08.
HttpGet httpGet =
new
HttpGet(urls[
0
]);
09.
httpGet.setHeader(
"Accept"
,
"application/json"
);
10.
httpGet.addHeader(
"Content-Type"
,
"application/json; charset=UTF-8"
);
11.
httpGet.addHeader(
"Access-Control-Allow-Origin"
,
"*"
);
12.
HttpResponse response = httpclient.execute(httpGet);
13.
HttpEntity entity = response.getEntity();
14.
15.
16.
String content = EntityUtils.toString(entity);
17.
JSONObject object =
new
JSONObject(content);
18.
19.
return
object;
20.
}
catch
(IOException e) {
21.
e.printStackTrace();
22.
}
catch
(JSONException e) {
23.
e.printStackTrace();
24.
}
25.
26.
return
null
;
27.
}
28.
}