我正在向android中的服务器发送一些数据,但作为一种共鸣,我得到的一些原始数据包含javascript和html,它们会在几秒钟内消失,是服务器响应数据发送,如果不是那么我必须做什么?,这里我使用的是AsyncTask类
这是我的班级
private class HttpAsyncTask extends AsyncTask<String, Void, String>{
@Override
protected String doInBackground(String... urls) {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://182.18.144.140:80");
String responseBody="";
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("LAT", lat));
nameValuePairs.add(new BasicNameValuePair("LON", lng));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
try {
HttpResponse response = httpclient.execute(httppost);
responseBody= EntityUtils.toString(response.getEntity());
String resp = response.getStatusLine().toString();
Toast.makeText(getBaseContext(), resp, 5000).show();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
catch (ClientProtocolException e) {
Toast.makeText(getBaseContext(), "Error", 5000).show();
}
} catch (IOException e) {
// TODO Auto-generated catch block
Log.i("HTTP Failed", e.toString());
}
return responseBody;
}
// onPostExecute displays the results of the AsyncTask.
@Override
protected void onPostExecute(String result) {
Toast.makeText(getBaseContext(), "Updated Server!"+result, Toast.LENGTH_LONG).show();
}
}