我尝试制作一个 AsyncTask 类以在后台上传可变温度。我如何插入参数?网址,变量?我制作了这段代码,但我有错误......
public class SimpleHttpPut extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
//public static void main(String urlt,int t) {
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(urlt);
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("temp",String.valueOf(t)));
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = client.execute(post);
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String line = "";
while ((line = rd.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
// }
return null;
}
protected void onPostExecute(Void result) {
}