嗨,我已经看完了中的文档https://forgerock.org/openam/doc/bootstrap/user-self-service-guide/index.html#configuring-忘记密码
API在海报和邮递员的帮助下运行良好。但当使用http从java字符串时,它不起作用,内部服务器正在获取。问题是什么?请帮忙。
public static void main(String a[]) throws IOException {
JSONObject data1 = new JSONObject();
JSONObject data = new JSONObject();
data.put("queryFilter", "mail eq 'test@gmail.com'");
data1.put("input", data);
System.out.println(data1);
Map<String, String> headers = new HashMap<String, String>();
HttpURLConnection connection = null;
try {
URL obj = new URL("http://localhost:8080/sso/json/sample/selfservice"
+ "/forgottenPassword?_action=submitRequirements");
connection = (HttpURLConnection) obj.openConnection();
connection.setRequestMethod("POST");
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setRequestProperty("Content-Type", "application/json");
if (headers != null && headers.size() > 0) {
Iterator it = headers.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pair = (Map.Entry) it.next();
connection.setRequestProperty((String) pair.getKey(),
(String) pair.getValue());
}
}
// Send request
DataOutputStream dataOutputStream = new DataOutputStream(
connection.getOutputStream());
dataOutputStream.writeBytes(data1.toString());
dataOutputStream.flush();
dataOutputStream.close();
// Get Response
System.out.println(connection.getResponseCode());
System.out.println(connection.getResponseMessage());
InputStream is = connection.getInputStream();
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
String line;
StringBuilder response = new StringBuilder();
while ((line = rd.readLine()) != null) {
response.append(line);
response.append('r');
}
rd.close();
is.close();
return response.toString();
} catch (MalformedURLException e) {
LOG.info("Error in sendPost : MalformedURLException " + e);
throw e;
} catch (ProtocolException e) {
LOG.info("Error in sendPost : ProtocolException " + e);
throw e;
} catch (IOException e) {
e.printStackTrace();
LOG.info("Error in sendPost : IOException "
+ e.getLocalizedMessage());
LOG.info("Error in sendPost : IOException " + e);
throw e;
} finally {
if (connection != null) {
connection.disconnect();
}
}}
我认为您只需要使用支持的区域设置请求的Accept-Language标头。