1
我調用方法在web服務返回字符串「真」或「假」,並使用下面的代碼JSON服務調用任何回報
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>
,並深信服務正在運行
我試過,但沒有迴應任何 – AMH
你試着用交數或沒有? – Akram
什麼ü郵寄數指的是代碼現在變成這樣:\t \t \t \t StringBuilder的URL =新的StringBuilder(); \t \t \t \t URL.append(「http://10.0.2.2:1539/WCFService1/Service.svc/Login/」); \t \t URL.append(username.getText()); \t \t URL.append(「/」); \t \t URL.append(password.getText()); – AMH