我遇到的情况是我从休息客户端调用目标api,请求参数为'yyyy-MM-dd HH:mm:ss'(对于startDate和endDate)我得到了预期的输出但是在做的时候同样来自我的应用程序,当我执行'.getInputStream()'时,它为 服务器返回HTTP响应代码:400为URL:Java.IO.Exception 。
这是我配置HTTPSConnection的地方。
private HttpsURLConnection setUsernamePasswordForConnectAPI(URL url) throws IOException {
HttpsURLConnection urlConnection = (HttpsURLConnection) url.openConnection();
String authString = username + ":" + password;
String authStringEnc = new String(Base64.encodeBase64(authString.getBytes()));
urlConnection.setRequestProperty("Authorization", "Basic " + authStringEnc);
urlConnection.setRequestMethod("GET");
urlConnection.setReadTimeout(requestTimeout);
urlConnection.connect();
return urlConnection;
}
当像下面提到的那样打电话时,我面临挑战。
String path = apiUrl + "/ignoreeventcount?startDate=" + fromDate + "&endDate=" + toDate;
StringBuilder sb = new StringBuilder();
URL url = new URL(path);
HttpsURLConnection urlConnection = (HttpsURLConnection)setUsernamePasswordForConnectAPI(url);
InputStream io = urlConnection.getInputStream();
这就是我从休息客户端调用我的控制器的方式。
localhost:8082/recon/fnolRecon?startDate=2017-12-19 00:01:00&endDate=2017-12-19 11:58:25
targetApi:
https://acorn-api.concirrus.com/v1/ignoreeventcount?startDate=2017-12-19 00:00:01&endDate=2017-12-19 23:59:59
我的控制器将请求参数作为字符串(开始日期和结束日期),我尝试将%20用于空格但无效
提前致谢。