【发布时间】:2021-10-26 11:12:14
【问题描述】:
当我从我的 linux 机器上执行以下 curl 命令时,我能够毫无问题地获得响应。
curl -X POST -H "Content-Type: text/xml" -H 'SOAPAction: "someAction"' -d '<soapenv:Envelope xmlns:soapenv="http://somenamespace/"> <soapenv:Header/> <soapenv:Body> DATA</soapenv:Body></soapenv:Envelope>' https://somewebservice/
但是当我尝试从 java 程序执行相同的命令时,它会抛出错误。 下面是我的代码 sn-p。
try {
String xmlInut = "'<soapenv:Envelope xmlns:soapenv=\"http://somenamespace/\"> <soapenv:Header/> <soapenv:Body> DATA</soapenv:Body></soapenv:Envelope>'"
String curlCommand = "curl -X POST -H \"Content-Type: text/xml\" -H 'SOAPAction: \"GenerateToken\"' -d "+xmlInput+" https://somewebservice/";
System.out.println(curlCommand);
Process process = Runtime.getRuntime().exec(curlCommand);
BufferedReader input = new BufferedReader(new InputStreamReader(process.getInputStream()));
outputString = "";
String line=null;
while((line=input.readLine())!=null)
{
outputString+=line;
}
System.out.println(outputString);
这是我遇到的错误
<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<soapenv:Fault>
<faultcode/>
<faultstring>com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character ''' (code 39) in prolog; expected '<' at [row,col {unknown-source}]: [1,1]
</faultstring></soapenv:Fault></soapenv:Body></soapenv:Envelope>
如何解决此错误?我在命名空间和数据周围尝试了单引号和双引号的各种组合,但它们都不起作用。 我需要从我的 java 代码中执行相同的 curl 命令。
【问题讨论】:
-
您是否需要通过 Java 运行 curl 才能调用远程 SOAP 端点?你可以通过 Java 代码做到这一点。