我在同一个域https://iconfig-sit.abc.com/iconfigadmin/api/config-category/ISSICT/ISSICE:ICEQA:ICEUI/configuration/中有一个休息服务.....在浏览器中运行该服务时,它运行良好,并返回200条代码以及数据。但是当我在Java代码中调用它返回204时,没有数据……不确定问题出在哪里?它可能需要设置更多的标头,但不确定哪个。下面是代码。
public Map<String, String> iconfig() throws Exception {
GetMethod getMethod=null;
Map<String, String> filesList1 = new LinkedHashMap<>();
try{
NTCredentials credentials = new NTCredentials("user","password","","domain");
HttpClient httpClient = new HttpClient();
httpClient.getState().setCredentials(AuthScope.ANY, credentials);
//httpClient.getParams().setAuthenticationPreemptive(true);
//httpClient.getState()
String serviceListQuery = "https://iconfig-sit.abc.com/iconfigadmin/api/config-category/ISSICT/ISSICE:ICEQA:ICEUI/configuration/oporders_bod_mismatch-source-grid";
System.out.println("List file query " + serviceListQuery );
getMethod = new GetMethod(serviceListQuery);
getMethod.addRequestHeader("Access-Control-Allow-Credentials","true");
getMethod.addRequestHeader("Access-Control-Allow-Origin","*");
getMethod.addRequestHeader("Accept","application/json");
getMethod.setRequestHeader("Content-Type", "application/json");
getMethod.setRequestHeader("prefer", "return=representation");
//getMethod.setDoAuthentication(true);
//getMethod.addRequestHeader("X-RequestDigest",formDigestValue);
int uploadFileResponseCode = httpClient.executeMethod(getMethod);
System.out.println(" List file query " + uploadFileResponseCode );
//if (uploadFileResponseCode == HttpStatus.OK.value()) {
byte[] responseBody = getMethod.getResponseBody();
System.out.println("Data" + responseBody );
JSONObject jsonObject = (JSONObject) new JSONParser().parse(responseBody);
if (jsonObject != null) {
JSONObject rootNode = (JSONObject) jsonObject.get("d");
JSONArray entries = (JSONArray) rootNode.get("results");
} //} else {
//logger.error("Unable to retrieve sharepoint documents url [" + sharepointServiceUrl + "]. HTTP Status = " + status); //}
}catch(Exception e){
System.out.println(e);
}finally { if (getMethod != null)
getMethod.releaseConnection(); }
return filesList1;
}