我正在尝试使用 Java 中的 Spring RestTemplate 的肥皂服务。我添加了一些 header 和请求参数,并将其分派(dispatch)到 PostForEntity 方法中,但它抛出 405 方法不允许。
我知道服务器将此调用视为 GET 的原因,但是它只能是 post 。 我尝试更改我的 header 并更改我的请求,但没有取得任何成果。有人可以建议我的方法/代码有什么问题吗?
String host = "172.18.101.2";
String port = "80";
System.out.println("Using proxy: " + host + ":" + port);
System.setProperty("https.proxyHost", host);
System.setProperty("https.proxyPort", port);
SSLUtilities.trustAllHostnames();
SSLUtilities.trustAllHttpsCertificates();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.TEXT_XML);
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
headers.add("SOAPAction", "http://ApiConnectFTwsdlDefinition/FundsTransfer");
headers.add("X-IBM-Client-Id", "0146b9a4-7e99-4c83-8e9e-6049cfec55da");
headers.add("Authorization", "Bearer AAIkMDE0NmI5YTQtN2U5OS00YzgzLThlOWUtNjA0OWNmZWM1NWRhV8EJd7oTPaijRicPTNxSH_h21meA_4h3Ty_QDOoXXRPC2f_MLk0BLBx4Q0DWZMHTfwTwur3BaiiF7y9uFcCkkj8fuTGK_yujrtuRY-4AZMK8hRPSppw3HhKYR84R9c9Wy9j6czOKqUklfLO6Zgb19A");
MultivaluedMap body = new MultivaluedHashMap();
JSONObject requestObj = new JSONObject();
requestObj.put("SystemName", "CDC");
requestObj.put("RequestID", "222");
requestObj.put("TenantID", "abc11323===+");
requestObj.put("CreditAccount", "0010000108290010");
requestObj.put("DebitAmount", "100");
requestObj.put("MappingID", "Remarks");
requestObj.put("Narration", "remarks");
body.add("data", requestObj.toString());
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<String> response = restTemplate.postForEntity("https://221.120.211.69:443/abl-api/uat/ApiConnectFTwsdlDefinitionHttpService?wsdl", requestObj.toString(), String.class);
System.out.println("Status Code >>> " + response.getStatusCode());
最佳答案
不要使用 RestTemplate
来使用 SOAP 服务,请使用 spring web services client
关于java - 使用 RestTemplate (POST) 使用 SOAP 服务抛出 405 Method Not allowed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60168516/