【发布时间】:2012-11-09 21:49:34
【问题描述】:
我正在尝试在必须通过的地方进行网络服务调用
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 对象,所以这也可能是错误的原因吗?
【问题讨论】:
-
异常没有意义。发布堆栈跟踪。
-
如果您提供错误可能会有所帮助。