我正在尝试httpPut方法。我不知道该怎么做。我正在尝试这个样本。
在日志中我得到了很长的痕迹..我能知道这条线意味着什么吗?
Http回复:org.apache.http.message.BasicHttpResponse@5273e44c 这意味着什么?
这是我的代码
public class AndroidHTTPRequestsActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Creating HTTP client
HttpClient httpClient = new DefaultHttpClient();
HttpPut httpPut=new HttpPut("http://www.google.com");
// Creating HTTP Post
// HttpPost httpPost = new HttpPost("http://www.example.com/login");
// Building post parameters
// key and value pair
List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>(2);
nameValuePair.add(new BasicNameValuePair("email", "user@gmail.com"));
nameValuePair.add(new BasicNameValuePair("message",
"Hi, trying Android HTTP post!"));
// Url Encoding the POST parameters
try {
httpPut.setEntity(new UrlEncodedFormEntity(nameValuePair));
} catch (UnsupportedEncodingException e) {
// writing error to Log
// e.printStackTrace();
}
// Making HTTP Request
try {
HttpResponse response = httpClient.execute(httpPut);
// writing response to log
System.out.println("Http Response:" +response.toString());
Log.d("Http Response:", response.toString());
} catch (ClientProtocolException e) {
// writing exception to log
// e.printStackTrace();
} catch (IOException e) {
// writing exception to log
// e.printStackTrace();
}
}
}
答案 0 :(得分:1)
尝试这样做以获得回复:
HttpEntity httpEntity = null;
httpEntity = response.getEntity();
response = EntityUtils.toString(httpEntity);
答案 1 :(得分:0)
Http Response:org.apache.http.message.BasicHttpResponse@5273e44c
指类BasicHttpResponse
的对象。