0
我没有收到任何回复,我的代码中存在什么问题。由于隐私政策,我没有提供正确的URl。如何在Android中使用post数据调用webservice
public static String URL = "http://www.example.com/web_service/mainAPI.php";
final String body = String.format("rquest={\"method\":\"upcoming_shows\",\"body\":[{}]}");
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.upcoming_show);
try{
Log.d("In Try", "Going...");
final HttpClient client = new DefaultHttpClient();
final HttpPost postMethod = new HttpPost(URL);
postMethod.setEntity(new StringEntity(body, "utf-8"));
final HttpResponse response = client.execute(postMethod);
final String responseData = EntityUtils.toString(response.getEntity(), "utf-8");
Toast.makeText(UpcomingShow.this, responseData, Toast.LENGTH_SHORT).show();
}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
请给我一些解决方案。
调试代码,看看是你不应该做网络相关的操作问题 – Shiv 2013-04-24 13:59:20
UIThread你应该使用asynctask或任何其他机制availabe – vinoth 2013-04-24 14:00:52
我敬酒ResponseData但没有数据是敬酒。它敬酒空白。 – RBL 2013-04-24 14:01:48