我已经写了一个独立的客户端来调用Json REST Service POST方法。
当我独立运行它时,我能够成功获得响应,但我得到了 我在weblogic服务器上部署时出现400 Bad Request错误。
我正在使用JDK 1.5和weblogic 10.3.0。
以下是代码:
String[] scope = { "openid", "profile", "email", "phone", "legacy" };
AuthTokenRequest authTokenRequest = new AuthTokenRequest();
authTokenRequest.setCode("685791bb-e39b-40a8-88f4-73a5fb7c01a");
authTokenRequest.setGrant_type("authorization_code");
URL url = new URL("https://api.ref.o2.co.uk/auth/v1/token");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("Authorization", authorizationHeader);
String input = "{\"code\":\"c88ae7e4-a2d4-4cc0-
aaeb16ca8a1467\",\"grant_type\":\"authorization_code\"}";
conn.getOutputStream().write(input.getBytes());
conn.getOutputStream().flush();
conn.getOutputStream().close();
BufferedReader br = new BufferedReader(new InputStreamReader((conn
.getInputStream())));
String output;System.out.println("Output from Server .... \n");while
((output = br.readLine()) != null) {
System.out.println(output);
}
conn.disconnect();