日期:2014-05-17  浏览次数:20944 次

PostMethod获取post提交的页面代码,如何处理URL中的空格
Document dom = null;
String soapRequestOfTargetService = "<SOAP:Envelope xmlns:SOAP=\"http://schemas.xmlsoap.org/soap/envelope/\">"
+"<SOAP:Body>"
+"<GetTask xmlns=\"http://schemas.cordys.com/notification/workflow/1.0\">"
+"<TaskId>"+taskId+"</TaskId>"
+"</GetTask>"
+"</SOAP:Body>"
+"</SOAP:Envelope>";
try{
PostMethod postmethod = new PostMethod("http://192.168.1.212/cordys/com.eibus.web.soap.Gateway.wcp?organization=o=Demo,cn=cordys,cn=defaultInst,o=comac.com&SAMLart=" + SAMLart);
byte[] b = soapRequestOfTargetService.getBytes("UTF-8");
InputStream is = new ByteArrayInputStream(b, 0, b.length);
RequestEntity re = new InputStreamRequestEntity(is, b.length, "application/xop+xml; charset=UTF-8; type=\"text/xml\"");
postmethod.setRequestEntity(re);
HttpClient httpClient = new HttpClient();
int statusCode = httpClient.executeMethod(postmethod);
System.err.println("statuscode = " + statusCode);
String soapResponseData = postmethod.getResponseBodyAsString();
System.out.println(soapResponseData);

DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
dom = builder.parse(postmethod.getResponseBodyAsStream());

}catch(Exception ex){
ex.printStackTrace();
}

如上代码,http://192.168.1.212/cordys/com.eibus.web.soap.Gateway.wcp?organization=o=Demo,cn=cordys,cn=defaultInst,o=comac.com&SAMLart=" + SAMLart中因为SAMLart的值包含空格,如SAMLart = "MDEYS/v6RyxKG3SDzjOCR8a8J0Ow3mWyIrl4uDN4H7AW5Aao8 5sXRKP",后台会出现错误

java.lang.IllegalArgumentException: Invalid uri 'http://192.168.1.212/cordys/com.eibus.web.soap.Gateway.wcp?organization=o=Demo,cn=cordys,cn=defaultInst,o=comac.com&SAMLart=MDEYS/v6RyxKG3SDzjOCR8a8J0Ow3mWyIrl4uDN4H7AW5Aao8 5sXRKP': Invalid query
at org.apache.commons.httpclient.HttpMethodBase.<init>(HttpMethodBase.java:222)
at org.apache.commons.httpclient.methods.ExpectContinueMethod.<init>(ExpectContinueMethod.java:93)
at org.apache.commons.httpclient.methods.EntityEnclosingMethod.<init>(EntityEnclosingMethod.java:119)
at org.apache.commons.httpclient.methods.PostMethod.<init>(PostMethod.java:106)
at com.richong.relia.warning.action.ManWarningAction.getSoapRequestOfTargetService(ManWarningAction.java:924)
at com.richong.relia.warning.action.ManWarningAction.toWarningWorkspace(ManWarningAction.java:295)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:452)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:291)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:254)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:248)
at com.opensymphon