栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > .Net

java 发送post请求 参数为xml

.Net 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

java 发送post请求 参数为xml

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

import java.io.OutputStreamWriter;

import java.net.MalformedURLException;

import java.net.URL;

import java.net.URLConnection;

public class HttpPostTest {

void testPost(String urlStr) {

try {

URL url = new URL(urlStr);

URLConnection con = url.openConnection();

con.setDoOutput(true);

con.setRequestProperty("Pragma:", "no-cache");

con.setRequestProperty("Cache-Control", "no-cache");

con.setRequestProperty("Content-Type", "text/xml");

OutputStreamWriter out = new OutputStreamWriter(con

.getOutputStream());

String xmlInfo = getXmlInfo();

System.out.println("urlStr=" + urlStr);

System.out.println("xmlInfo=" + xmlInfo);

out.write(new String(xmlInfo.getBytes("ISO-8859-1")));

out.flush();

out.close();

BufferedReader br = new BufferedReader(new InputStreamReader(con

.getInputStream()));

String line = "";

for (line = br.readLine(); line != null; line = br.readLine()) {

System.out.println(line);

}

} catch (MalformedURLException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

}

private String getXmlInfo() {

StringBuilder sb = new StringBuilder();

sb.append("");

sb.append(" ");

sb.append(" 1");

sb.append(" service");

sb.append(" ");

sb.append(" ");

sb.append(" 0000021000011001");

sb.append(" 33647405");

sb.append(" mnt/5.0.217.50/resources/80009.mov");

sb.append(" 0000021000011001");

sb.append(" ");

sb.append("");

return sb.toString();

}

public static void main(String[] args) {

String url = "http://5.0.217.50:17001/VideoSend";

new HttpPostTest().testPost(url);

}

}

转自:http://a52071453.iteye.com/blog/1706949

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/984469.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号