中提供的文件
API从海报和邮递员处理得很好。但是,当使用http从而使用它不起作用时,内部服务器正在增加。什么是问题?请帮助。
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();
}
}}
答案 0 :(得分:0)
我认为您只需要使用受支持的区域设置在请求上设置Accept-Language标头。