有一个A系统,使用WebService接口方式提供远程服务,我们现在想向这个接口发送XML文件第一种方式:
1)HTTP的POST方式向A系统发送XML文件,2)HTTPS方式向A系统发送XML文件,请问如何实现,着急,有分哦!
知道的请与我联系:
邮箱:[email protected]给个例子的代码最好,呵呵
1)HTTP的POST方式向A系统发送XML文件,2)HTTPS方式向A系统发送XML文件,请问如何实现,着急,有分哦!
知道的请与我联系:
邮箱:[email protected]给个例子的代码最好,呵呵
解决方案 »
- struts中的某个action怎么配置不用登陆也可以访问?
- java中string和stringbuffer的问题
- Struts form提交乱码问题
- Struts2 使用什么方法上传文件好呢
- 求一个可运行Struts2实例!(如:HelloWorld)!
- 我的注册页面有问题!!!帮忙看下吧,谢谢~~~
- 关于spring AOP 的配置方式!
- 求救:Struts的基础问题(关于流程问题)
- 万谢!请问jboss-3.2.1_tomcat-4.1.24中如何和配置Oracle8i连接池
- 一个初手写了一个可能问题比较多的程序,请各位高手指点? (每天有心得)
- java web service 问题
- xfire连接到.NET的webservice问题
不必要传文件
谢谢,我们是把XML进行BASE64编码,然后通过ContentType须为“application/octet-stream”,即为字节流方式传递
我通过 c# 把 要传递的内容传到服务器上的 HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(RequestAddress);
req.Method = "POST";
req.KeepAlive = false;
req.ContentType = "application/x-www-form-urlencoded;charset=" + Encoding.ToString();
req.ContentLength = postBytes.Length;你看看对你有没有用处,
这里面少了 参数的设置
try{
// HttpClient httpClient = new HttpClient();
String StrSoapMsg="<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:web=\"http://WebXml.com.cn/\">"
+"<soap:Header/>"
+"<soap:Body>"
+"<web:getWeatherbyCityName>"
+"<web:theCityName>beijing</web:theCityName>"
+"</web:getWeatherbyCityName>"
+"</soap:Body>"
+"</soap:Envelope>";
String Url = strUrlService;
URL url = new URL(Url);
URLConnection connection = url.openConnection();
HttpURLConnection httpConn = (HttpURLConnection) connection;
httpConn.setDoOutput(true);
httpConn.setDoInput(true);
httpConn.setRequestMethod("POST");
httpConn.setRequestProperty("Content-Type","application/soap+xml; charset=utf-8");//这里根据服务器情况看 一种是//application/soap+xml 还有一种是text/xml httpConn.setRequestProperty("SOAPAction", "http://www.webxml.com.cn/WebServices/WeatherWebService.asmx");
OutputStream out = httpConn.getOutputStream();
Writer wout = new OutputStreamWriter(out);
wout.write(StrSoapMsg.trim());
wout.flush();
wout.close();
/* BufferedReader rd = new BufferedReader(new InputStreamReader(httpConn.getInputStream()));
String line = "";
while ((line = rd.readLine()) != null) {
System.out.print( line); }*/
InputStreamReader isr = new InputStreamReader(httpConn.getInputStream());
char[] ok = new char[1024*2] ;
String strRead = "";
int i = 0 ;
while (true){
i = i+1;
if (i == iGetStrLong){
break ;
}
if (isr.read(ok)== -1){
strRead = strRead + (new String(ok)).trim() ;
break;
}
else{
strRead = strRead + (new String(ok)).trim() ;
ok = null;
ok = new char[1024*20] ;
}
}
strRead = strRead.trim();
isr.close();
System.out.print(strRead.toString());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
结贴吧 发送返回全给你写了 你只需要把发送的xml换下就行了
URL url = new URL(Url);
URLConnection connection = url.openConnection();
HttpURLConnection httpConn = (HttpURLConnection) connection;
httpConn.setDoOutput(true);
httpConn.setDoInput(true);
httpConn.setRequestMethod("POST");
httpConn.setRequestProperty("Content-Type","application/soap+xml; charset=utf-8");
JDOM读取更简单些