我正在尝试使用下面的网络服务
http://62.253.195.179/disaster/webservices/login.php?message=[{"email":"ugo.amanoh@transputec.com","password":"welcome"}]
这将返回一个 JSON 数组
[{"companyuserId":"2","name":"ben stein","superiorname":"Leon","departmentId":"26","departmentname":"Development","companyId":"23","UDID":"12345","isActive":"1","devicetoken":"12345","email":"ugo.amah@transputec.com","phone":"5456465465654","userrole":"1","chngpwdStatus":"1"}]
我的代码如下
try{
String weblink = URLEncoder.encode("http://62.253.195.179/disaster/webservices/login.php?message=[{\"email\":\"ugo.amanoh@transputec.com\",\"password\":\"welcome\"}]");
HttpParams httpParameters = new BasicHttpParams();
int timeoutConnection = 7500;
HttpConnectionParams.setConnectionTimeout(httpParameters,
timeoutConnection);
int timeoutSocket = 7500;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
HttpClient client = new DefaultHttpClient(httpParameters);
HttpGet request = new HttpGet();
URI link = new URI(weblink);
request.setURI(link);
HttpResponse response = client.execute(request);
BufferedReader rd = new BufferedReader(new InputStreamReader(
response.getEntity().getContent()));
result = rd.readLine();
JSONObject myData = new JSONObject(result);
JSONArray jArray = myData.getJSONArray("");
JSONObject steps = jArray.getJSONObject(0);
String name = steps.getString("name");
} catch (JSONException e) {
e.printStackTrace();
}
但它不起作用,我不能 100% 确定这是最好的方法。
11-10 10:49:55.489: E/AndroidRuntime(392): java.lang.IllegalStateException: Target host must not be null, or set in parameters.