Ama*_*nni 0 java string escaping http
我正试图在我必须通过的网络服务电话
login.php?message=[{"email":"mikeymike@mouse.com","password":"tiger"}]
Run Code Online (Sandbox Code Playgroud)
我使用反斜杠来逃避这样的双引号
String weblink = "login.php?message=[{\"email\":\"mikeymike@mouse.com\",\"password\":\"tiger\"}]";
Run Code Online (Sandbox Code Playgroud)
但我仍然遇到错误.我试过调用其他没有任何双引号需要数据的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
Run Code Online (Sandbox Code Playgroud)
编辑:我已经尝试使用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;
}
Run Code Online (Sandbox Code Playgroud)
webservice也返回一个JSON对象,这也可能是错误的原因吗?
而不是手动尝试并获取错误,为什么不使用JSONObject类和UrlEncoder 的组合.
JSONObject json = new JSONObject();
json.put("email","mikeymike@mouse.com" );
json.put("password", "tiger");
String s = "login.php?message=" + UrlEncoder.encode(json.toString());
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5559 次 |
| 最近记录: |