【发布时间】:2020-02-17 20:35:33
【问题描述】:
我正在使用 Okhttp 客户端获取基于 Rest API 的 OAuth 2.0 令牌。
当我在 Weblogic 12c 上部署它时,它显示错误 java.io.IOException: Unexpected response code for CONNECT: 400
我尝试以不同样式更改实现和标头方法方法可能是我的请求失败,因为我提供了错误的凭据但没有任何改变。
谁能建议我在我的代码中做错了什么?
客户代码
public String Post (String url, String json) throws IOException {
Response response = null;
try {
logger.info("FMS WEBSERVICE LOG >>> Posting method...");
RequestBody body = RequestBody.create(JSON, json);
logger.info("FMS WEBSERVICE LOG >>> body: " + body);
Request request = new Request.Builder().url(url).post(body).build();
logger.info("FMS WEBSERVICE LOG >>> request: " + request);
response = client.newCall(request).execute();
logger.info("FMS WEBSERVICE LOG >>> returning: " + response.toString());
}
catch (Exception e) {
logger.info("FMS WEBSERVICE LOG >>> exception in WebServiceClient: " + e);
}
return response.body().string();
}
@GET
@Path("/fundTransfer")
@Produces(javax.ws.rs.core.MediaType.APPLICATION_JSON)
public String soapCaller() throws IOException, JSONException {
logger.info("FMS WEBSERVICE LOG >>> Inside the client method");
String json = new StringBuilder()
.append("{")
.append("\"grant_type\":\"client_credentials\",")
.append("\"client_id\":\"0146b9a4-7e99-4c83-8e9e-6049cfec55da\",")
.append("\"client_secret\":\"nY3oL5xQ3bJ8yT3nC1nV5bY4mY6eW7yP1nY6dS6rQ2nE5iR0rM\",")
.append("\"scope\":\"ABLApis\"")
.append("}").toString();
logger.info("FMS WEBSERVICE LOG >>> JSON >>> " + json.toString());
String response = Post("https://221.120.211.69:443/abl-api/uat/oauth2/token", json);
logger.info("FMS WEBSERVICE LOG >>> response >>> " + response);
return response;
}
我正在使用邮递员通过以下网址点击 GET 请求:http:///FMS_WEB_SERVICES/fmsServices/fundTransfer
【问题讨论】: