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("<videoSend>");
sb.append(" <header>");
sb.append(" <sid>1</sid>");
sb.append(" <type>service</type>");
sb.append(" </header>");
sb.append(" <service name=\"videoSend\">");
sb.append(" <fromNum>0000021000011001</fromNum>");
sb.append(" <toNum>33647405</toNum>");
sb.append(" <videoPath>mnt/5.0.217.50/resources/80009.mov</videoPath>");
sb.append(" <chargeNumber>0000021000011001</chargeNumber>");
sb.append(" </service>");
sb.append("</videoSend>");
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

提交post请求,参数为xml格式的更多相关文章

  1. webservice接口测试wsdl,参数是xml格式。python,入参转化成str,返回值转化成dict调用

    1.用SoapUI测试webservice接口,传入参数是xml格式时.xml格式需要将xml的外围增加<![CDATA[xml]]> 2.但是用python去做webservice测试, ...

  2. ajax数据请求4(xml格式)

    ajax数据请求4(xml格式): <!doctype html> <html> <head> <meta charset="utf-8" ...

  3. 返回参数去掉xml格式,以纯json格式返回(转)

    Json 格式显示public static void Register(HttpConfiguration config) { //////////////设置不以xml格式返回 config.Fo ...

  4. 使用soapUI5.3.0调试webservice接口(参数为XML格式)

    最近项目中经常要调试webservice接口,从朋友处了解到他们经常使用SoapUI,因此学习一下这个工具的使用,为避免遗忘,特地记录下来,分享分享... 下载 #####首先,下载SoapUI,我下 ...

  5. requset获取post提交的请求参数

    1.请求体的内容通常是通过post来提交的,格式是 username=zhansan&password=123&hobby=football||&hobby=basketbal ...

  6. 对于java用发送http请求,请求内容为xml格式

    import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.ByteArrayOutputStr ...

  7. java发送http请求,内容为xml格式&&传统URI类请求

    import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.ByteArrayOutputStr ...

  8. soapUI测试webservice(参数为xml格式的处理方式)

    如果传递的是xml,要用<![CDATA[   ]]>将xml注释为字符串 示例 <?xml version="1.0" encoding="UTF-8 ...

  9. 使用axios请求数据,post请求出错。因为axios传递的请求参数是json格式,而后端接口要求是formData

    解决办法1:(IOS兼容性有问题,不推荐使用) // json格式转为formData格式,因为某些接口的原因 function json2formData(jsonData) { var param ...

随机推荐

  1. java基础之集合长度可变的实现原理

    首先我们要明白java中的集合Collection,List,ArrayList之间的关系: ArrayList是具体的实现类,实现了List接口 List是接口,继承了Collection接口 Li ...

  2. codeforce 461DIV2 E题

    题意 有n棵树排成一排,每个树上都有c[i]只小鸟,只有站在树下才可以召唤小鸟,在i-th树下召唤k(k<=c[i])只小鸟需要消耗cost[i]*k的法力值,但是每召唤一只小鸟可以将法力值的上 ...

  3. 使用laravel实现用户的登陆

    首先在 php artisan 里面 make:auth 生产一个门脸类 修改配置文件里面要哪个模型登陆 模型得继承一下才能 先写一下注册 密码必须要使用laravel的加密方法,使用MD5都没用 l ...

  4. (二)在eclipse中使用maven

    二.配置Maven插件 2.1.配置使用的Maven

  5. php+mysql网站无限级栏目分类-递归获取树形结构函数

    如果网站采用了无限级栏目结构,我们可以将网站所有栏目获取出来组成一个树形结构.数据库结构: 函数代码: //获得指定文章分类的子分类组成的树形结构 function cateTree($pid=0,$ ...

  6. 594. Longest Harmonious Subsequence强制差距为1的最长连续

    [抄题]: We define a harmonious array is an array where the difference between its maximum value and it ...

  7. Docker学习笔记_网上资源参考

    Docker学习,网上资源参考 1.菜鸟教程:                                                        http://www.runoob.com ...

  8. ESP8266文档阅读ESP8266 SDK 入门指南

    ESP8266 SDK  入门指南 1.概述 1.2.ESP8266 HDK 1.3.ESP8266 SDK 1.4.ESP8266 FW 1.5.ESP8266 工具集 2.1.开发板方案 3.软件 ...

  9. Oracle——分组函数

    AVG(平均值)和 SUM (合计)函数 可以对数值型数据使用AVG 和 SUM 函数. AVG组函数忽略空值 --在组函数中使用NVL函数 --求平均值 )) MIN(最小值)和 MAX(最大值)函 ...

  10. IntelliJ IDEA——maven环境下整合SSM

    SSM整合目录结构 开发环境:JDK1.8:apache-tomcat-7.0.52 : MySql5.7 开发工具:IntelliJ IDEA pom.xml <?xml version=&q ...