HttpClient Client = new DefaultHttpClient();
String URL = "http://192.168.2.22:1099/Service1.svc/test";
try
{
String setServerString = "";
HttpGet httpget = new HttpGet(URL);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
setServerString = Client.execute(httpget, responseHandler);
lblStatus.setText(setServerString);
}
catch(Exception ex)
{
lblStatus.setText("Fail!");
}
当我们调用 url 时,它返回一个字符串并设置为 lblStatus。此代码在 v2.3.* 中运行良好,但在 v4.0 中无法运行。我能够在 v2.3.* 版本中获取字符串,但在 v4.0 中没有。