gpt4 book ai didi

java - 在 Java 中使用 Autotask API 查询帐户

转载 作者:行者123 更新时间:2023-11-29 04:06:47 26 4
gpt4 key购买 nike

我一直在尝试使用 Java 中的 Autotask API,但没有成功。我正在像这样构建 SOAP 消息:

SOAPMessage soapMessage = messageFactory.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
soapEnvelope.addNamespaceDeclaration("atns", AUTOTASK_NAMESPACE);
MimeHeaders soapHeaders = soapMessage.getMimeHeaders();
String authorization = Base64Utils.encodeBasicAuthorization(username, password);
soapHeaders.addHeader("Authorization", "Basic " + authorization);
if (!StringUtils.isBlank(integrationCode)) {
SOAPElement autotaskIntegrationsElement = soapMessage.getSOAPHeader().addChildElement("AutotaskIntegrations", null, AUTOTASK_NAMESPACE);
SOAPElement integrationCodeElement = autotaskIntegrationsElement.addChildElement("IntegrationCode");
integrationCodeElement.setTextContent(integrationCode);
}
SOAPBody soapBody = soapMessage.getSOAPBody();
SOAPElement methodElement = soapBody.addChildElement("query", "atns");
CDATASection query = soapMessage.getSOAPPart().createCDATASection(queryXml));
methodElement.appendChild(query);
SOAPMessage soapResponse = soapConnection.call(soapMessage, defaultZoneUrl);

这将返回一个 ATWSError。我做错了什么?

最佳答案

您缺少 sXML 元素:

SOAPMessage soapMessage = messageFactory.createMessage();
SOAPPart soapPart = soapMessage.getSOAPPart();
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
soapEnvelope.addNamespaceDeclaration("atns", AUTOTASK_NAMESPACE);
MimeHeaders soapHeaders = soapMessage.getMimeHeaders();
String authorization = Base64Utils.encodeBasicAuthorization(username, password);
soapHeaders.addHeader("Authorization", "Basic " + authorization);
if (!StringUtils.isBlank(integrationCode)) {
SOAPElement autotaskIntegrationsElement = soapMessage.getSOAPHeader().addChildElement("AutotaskIntegrations", null, AUTOTASK_NAMESPACE);
SOAPElement integrationCodeElement = autotaskIntegrationsElement.addChildElement("IntegrationCode");
integrationCodeElement.setTextContent(integrationCode);
}
SOAPBody soapBody = soapMessage.getSOAPBody();
SOAPElement methodElement = soapBody.addChildElement("query", "atns");
SOAPElement sxmlElement = methodElement.addChildElement("sXML", "atns");
CDATASection query = soapMessage.getSOAPPart().createCDATASection(queryXml));
sxmlElement.appendChild(query);
SOAPMessage soapResponse = soapConnection.call(soapMessage, defaultZoneUrl);

这应该有效。

关于java - 在 Java 中使用 Autotask API 查询帐户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58097254/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com