2013-04-24 58 views
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(); 
     } 

请给我一些解决方案。

+0

调试代码,看看是你不应该做网络相关的操作问题 – Shiv 2013-04-24 13:59:20

+0

UIThread你应该使用asynctask或任何其他机制availabe – vinoth 2013-04-24 14:00:52

+0

我敬酒ResponseData但没有数据是敬酒。它敬酒空白。 – RBL 2013-04-24 14:01:48

回答

2
  1. 您正在尝试访问UI线程上的网络,这不再允许。请参阅here。和here
  2. 你可能有一个错字在你String body,它说rquest,我认为它应该是request(第2行)
相关问题