我正在尝试联系 API 并获得响应。作为调试的一部分,我想确保正在记录响应,它应该是一个 xml 响应。
这是我所拥有的:
公共类 http 扩展 Activity {
public void httpMethod(){
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://site.com/api/");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("apikey", "0d4e122d20"));
nameValuePairs.add(new BasicNameValuePair("ip", "65.82.126.103"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
TextView myTextView = (TextView) findViewById(R.id.myTextView);
myTextView.setText(response);
}
}
我正在尝试查看我得到的响应,但是该行中的可变响应
myTextView.setText(response)
正在引发错误:
response cannot be resolved to a variable
响应不是真正的 httpresponse 类型的变量吗?这里发生了什么...?