我正在尝试在必须通过的地方进行网络服务调用
login.php?message=[{"email":"mikeymike@mouse.com","password":"tiger"}]
我已经使用反斜杠来转义这样的双引号
String weblink = "login.php?message=[{\"email\":\"mikeymike@mouse.com\",\"password\":\"tiger\"}]";
但我仍然遇到错误。我尝试过调用其他不需要带有任何双引号的数据的 web 服务,它们工作正常,所以我很确定问题出在这个问题上。我也得到一个 java.lang 异常说
java.lang.Exception Indicates a serious configuration error.DateParseException An exception to indicate an error parsing a date string. DestroyFailedException Signals that the destroy() method failed
编辑:我尝试使用 URLEncoder 和 JSON 对象,但仍然出现错误
这是其余的代码
String HOST = "http://62.285.107.329/disaster/webservices/";
String weblink = "login.php?message=[{\"email\":\"mikeymike@mouse.com\",\"password\":\"tiger\"}]";
String result = callWebservice(weblink);
public String callWebservice(String weblink) {
String result = "";
try {
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(HOST + weblink);
request.setURI(link);
HttpResponse response = client.execute(request);
BufferedReader rd = new BufferedReader(new InputStreamReader(
response.getEntity().getContent()));
result = rd.readLine();
} catch (Exception e1) {
e1.printStackTrace();
result = "timeout";
}
return result;
}
Web 服务还返回一个 JSON 对象,所以这也可能是错误的原因吗?