我在 webservice 中调用返回字符串“true”或“false”的方法,并使用以下代码获取两个参数
String isLogedin = readTwitterFeed();
public String readTwitterFeed() {
String Result = null;
StringBuilder URL = new StringBuilder();
URL.append("http://localhost:1539/WCFService1/Service.svc/Login/");
URL.append(username.getText());
URL.append("/");
URL.append(password.getText());
/////////////////////////////
HttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(
URL.toString());
try {
HttpResponse response = client.execute(httpGet);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode == 200) {
HttpEntity entity = response.getEntity();
InputStream content = entity.getContent();
BufferedReader reader = new BufferedReader(
new InputStreamReader(content));
StringBuilder builder = null ;
String line = null;
while ((line = reader.readLine()) != null) {
builder.append(line);
}
Result = builder.toString() ;
} else {
Result = "error";
}
} catch (ClientProtocolException e) {
Result = "error";
e.printStackTrace();
} catch (IOException e) {
Result = "error";
e.printStackTrace();
}
return Result;
}
但返回的字符串始终为空
知道为什么它不返回数据,也不显示任何错误(我在 textview 上显示返回值),我也设置了这样的互联网权限
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
并确定该服务正在运行