电信彩信附件,webservice HttpURLConnection
原先用 gSOAP 开发过一个,所发送的彩信(电信),附件中的图片可以打开。
生产环境中必须用 java,用 axis 开发出来的,所发送的彩信,附件中的图片无法打开。
解决方式:
1、用 wireshark 抓取正常的彩信包;
2、用 HttpURLConnection 直接发送:
private void testMMS(String boundary, String start, byte[] requestData) throws Exception{
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
connection.setUseCaches(false);
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestProperty("User-Agent", "kSOAP/2.0");
connection.setRequestProperty("SOAPAction", "");
connection.setRequestProperty("Content-Type", "multipart/related; charset=utf-8; " +
"boundary=\""+boundary+"\"; " +
"type=\"text/xml\"; start=\"<"+start+">\"");
connection.setRequestProperty("Connection", "close");
connection.setRequestProperty("Content-Length", "" + requestData.length);
connection.setRequestMethod("POST");
connection.connect();
OutputStream os = connection.getOutputStream();
System.out.println( "245_requestData.length:" + requestData.length );
os.write(requestData, 0, requestData.length);
os.flush();
os.close();
requestData = null;
InputStream is;
try {
connection.connect();
is = connection.getInputStream();
} catch (IOException e) {
e.printStackTrace();
is = connection.getErrorStream();
System.out.println("is:" + is);
if (is == null) {
connection.disconnect();
throw (e);
}
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buf = new byte[256];
while (true) {
int rd = is.read(buf, 0, 256);
if (rd == -1)
break;
bos.write(buf, 0, rd);
}
bos.flush();
buf = bos.toByteArray();
responseDump = new String(buf);
System.out.println("responseDump:" + responseDump);
is.close();
is = new ByteArrayInputStream(buf);
}
这段代码,是从 kSOAP 里扒出来的。
在研究过程中,因为对 webservice 的附件不太了解,还参考了 axis 的源码。
分享到:
相关推荐
Java原生HttpUrlConnection访问WebService实例,附相关jar包...新手整理不喜勿喷
彩信协议Webservice,接口描述彩信协议Webservice,接口描述
自己开发的一个手机彩信web service
WebService 附件 大附件 多附件
JAVA代码里,HttpURLConnection获取webservice的值,包含W3C解析XML节点方法
使用HttpURLConnection直接调用.net的WebService
使用Webservice实现大容量附件上传
带附件的webservice,详细讲解webservice如何携带附件通信
webservice摘录webservice摘录webservice摘录webservice摘录webservice摘录webservice摘录webservice摘录webservice摘录webservice摘录质
泛微OA系统工作流WebService接口使用说明.doc,含调用实例.....................................................................................................................................................
PHP webservice传输附件和文章源码: 有家公司专门搞PHP的写此接口,搞了个把月最后文章能传输,附件传不过去,,交给我花了2天的时间搞定。.
springboot+webservice搭建webservice服务端及使用java客户端两种方式进行调用
JAVA 短信系统客户端调用电信接口,JAVA 短信系统客户端调用电信接口.
调用WebService,最简单的办法当然是直接添加WEB引用,然后自动产生代理类,但是在调用JAVA的WebService时并没有这么简单,特别是对于SoapHeader的处理,通过C#添加Web引用方式访问JavaWebService的方法,除了string...
测试webService;webservice测试调用工具WebserviceStudio20
springboot+webservice搭建webservice服务端及使用java客户端两种方式进行调用webservice接口
WebService练习WebService练习WebService练习WebService练习
通过idea实现webservice
webservice接口一个或多个附件上传
webservice