提交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("<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格式的更多相关文章
- webservice接口测试wsdl,参数是xml格式。python,入参转化成str,返回值转化成dict调用
1.用SoapUI测试webservice接口,传入参数是xml格式时.xml格式需要将xml的外围增加<![CDATA[xml]]> 2.但是用python去做webservice测试, ...
- ajax数据请求4(xml格式)
ajax数据请求4(xml格式): <!doctype html> <html> <head> <meta charset="utf-8" ...
- 返回参数去掉xml格式,以纯json格式返回(转)
Json 格式显示public static void Register(HttpConfiguration config) { //////////////设置不以xml格式返回 config.Fo ...
- 使用soapUI5.3.0调试webservice接口(参数为XML格式)
最近项目中经常要调试webservice接口,从朋友处了解到他们经常使用SoapUI,因此学习一下这个工具的使用,为避免遗忘,特地记录下来,分享分享... 下载 #####首先,下载SoapUI,我下 ...
- requset获取post提交的请求参数
1.请求体的内容通常是通过post来提交的,格式是 username=zhansan&password=123&hobby=football||&hobby=basketbal ...
- 对于java用发送http请求,请求内容为xml格式
import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.ByteArrayOutputStr ...
- java发送http请求,内容为xml格式&&传统URI类请求
import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.ByteArrayOutputStr ...
- soapUI测试webservice(参数为xml格式的处理方式)
如果传递的是xml,要用<![CDATA[ ]]>将xml注释为字符串 示例 <?xml version="1.0" encoding="UTF-8 ...
- 使用axios请求数据,post请求出错。因为axios传递的请求参数是json格式,而后端接口要求是formData
解决办法1:(IOS兼容性有问题,不推荐使用) // json格式转为formData格式,因为某些接口的原因 function json2formData(jsonData) { var param ...
随机推荐
- Java 实现分页功能
driver=com.mysql.jdbc.Driver url=jdbc:mysql://localhost:3306/test?allowMultiQueries=true&useUnic ...
- Windows Cmder
一.简介 作为一个程序员,即使是在windows工作环境,cmd也是我们必不可少的使用工具.cmder 是为 Windows 提供的一个便携式控制台仿真器,用来替代windows的cmd,使用非常简单 ...
- jQuery--左侧菜单收缩隐藏
实现步骤: 步骤一. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 ...
- Installing XGBoost on Mac OSX
0. Get gcc with open mp. Just paste and execute the following command in your terminal, once Home ...
- Python 函数习题
#encoding=utf-8 from urllib.request import urlopen import random import os ''' 1. 定义一个fuc(url, folde ...
- yum 安装telnet
检测是否安装 rpm -qa |grep telnet 安装 yum install xinetd yum install telnet-server yum -y install telnet 再次 ...
- easyUI Methods
doc对象转jQuery 对象 $(doc Object); jQuery Object.控件名('方法'[,参数]); options 为该控件的属性 方式一: var opts = $('.eas ...
- 停止Nginx服务
查询nginx进程信息 chen@ubuntu:~$ ps -ef |grep nginx root : ? :: nginx: master process /usr/sbin/nginx -g d ...
- C#ADO.NET基础二
DataAdapter的使用,批量增删改 1.使用DataAdapter查询 private void Select2() { try { using (SQLiteConnection conn = ...
- .net core in Docker 部署方案(随笔)
前一段时间由于项目需要 .net core 在docker下的部署,途中也遇到很多坑,看了各同行的博客觉得多多少少还是有些问题,原本不想写此篇文章,由于好友最近公司也需要部署,硬是要求,于是花了些时间 ...