JAVA 如何实现HTTP的POST方式通讯,以及HTTPS方式传递

小瑞 2009-06-19 04:44:34
有一个A系统,使用WebService接口方式提供远程服务,我们现在想向这个接口发送XML文件

第一种方式:
1)HTTP的POST方式向A系统发送XML文件,

2)HTTPS方式向A系统发送XML文件,

请问如何实现,着急,有分哦!
知道的请与我联系:
邮箱:xiaxiaorui2003@163.com

给个例子的代码最好,呵呵
...全文
1780 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
hui5390094 2009-07-13
  • 打赏
  • 举报
回复
顶下
appleqwfyhw 2009-07-13
  • 打赏
  • 举报
回复
private static void processData() {


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换下就行了
  • 打赏
  • 举报
回复
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");




JDOM读取更简单些
gianlian_1 2009-07-11
  • 打赏
  • 举报
回复
hehe ,帮你顶一下.
liwenxian100 2009-07-05
  • 打赏
  • 举报
回复
顶下
pathuang68 2009-07-05
  • 打赏
  • 举报
回复
小瑞 2009-06-29
  • 打赏
  • 举报
回复
zhaodalong 2009-06-28
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 xiaxiaorui2003 的回复:]
另外,这些方式和JAVA的socket通信有什么不同呢,呵呵,现在着急要,先提问,晚上回家我再好好百度去。

多谢啊
[/Quote]
这样好
laorer 2009-06-22
  • 打赏
  • 举报
回复

我通过 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;

你看看对你有没有用处,
这里面少了 参数的设置
zabaglione 2009-06-22
  • 打赏
  • 举报
回复
用httpClientl来通信。

具体例子很多啊。baidu一下

google现在不好用了。被D封了。
angel6709 2009-06-22
  • 打赏
  • 举报
回复
ding
landyshouguo 2009-06-20
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 laorer 的回复:]
一个建议, 你直接把 xml 文件 放到字符串中,然后把这个字符串放到一个 input 中, 直接 用 httpclient post 过去就行了
不必要传文件
[/Quote]顶
小瑞 2009-06-19
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 laorer 的回复:]
一个建议, 你直接把 xml 文件 放到字符串中,然后把这个字符串放到一个 input 中, 直接 用 httpclient post 过去就行了
不必要传文件
[/Quote]

谢谢,我们是把XML进行BASE64编码,然后通过ContentType须为“application/octet-stream”,即为字节流方式传递
laorer 2009-06-19
  • 打赏
  • 举报
回复
一个建议, 你直接把 xml 文件 放到字符串中,然后把这个字符串放到一个 input 中, 直接 用 httpclient post 过去就行了
不必要传文件
小瑞 2009-06-19
  • 打赏
  • 举报
回复
另外,这些方式和JAVA的socket通信有什么不同呢,呵呵,现在着急要,先提问,晚上回家我再好好百度去。

多谢啊

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧