我使用soapui调用是正常的,但是使用java调用后一直报错,不知道问题出现在哪里
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import org.jfree.util.Log;
public class TestPost {
/**
* @param args
*/
public static void main(String[] args) {
StringBuffer sb = new StringBuffer();
sb.append("<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:tem=\"http://tempuri.org/\">");
sb.append("<soap:Header>");
sb.append("<a:To s:mustUnderstand=\"1\" xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:a=\"http://www.w3.org/2005/08/addressing\">http://localhost:8899/SmatPrintService</a:To>");
sb.append("</soap:Header>");
sb.append("<soap:Body>");
sb.append("<tem:PrintLabel>");
sb.append("<tem:pagecount>1</tem:pagecount>");
sb.append("<tem:printname>Send To OneNote 2016</tem:printname>");
sb.append("<tem:labelpath>C:\\workspace\\MLSMESClientProject1\\labs\\aaa.btw</tem:labelpath>");
sb.append("<tem:dicy>aa:123456</tem:dicy>");
sb.append("</tem:PrintLabel>");
sb.append("</soap:Body>");
sb.append("</soap:Envelope>");
System.out.println(sb.toString());
String address = "http://desktop-8mf1qs2:8899/SmatPrintService?wsdl";
try {
URL u = new URL(address);
HttpURLConnection uc = (HttpURLConnection) u.openConnection();
uc.setDoOutput(true);
uc.setRequestProperty("Content-Type",
"application/soap+xml;charset=utf-8");
uc.setRequestProperty("Charset", "UTF-8");
uc.setRequestMethod("GET");
uc.setDoOutput(true);
uc.setDoInput(true);
OutputStreamWriter osw = new OutputStreamWriter(uc
.getOutputStream(), "UTF-8");
osw.write(sb.toString());
osw.flush();
osw.close();
BufferedReader rd = new BufferedReader(new InputStreamReader(uc
.getInputStream(), "UTF-8"));
StringBuffer sbuffer = new StringBuffer();
int ch;
while ((ch = rd.read()) > -1) {
sbuffer.append((char) ch);
}
String rec_string = sbuffer.toString().trim();
System.out.println("返回数据:" + rec_string);
rd.close();
} catch (MalformedURLException e) {
Log.error(e.getMessage());
} catch (IOException e) {
Log.error(e.getMessage());
System.out.println(e.getMessage());
}
}
}
报错如下:
Server returned HTTP response code: 500 for URL: http://desktop-8mf1qs2:8899/SmatPrintService?wsdl