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