欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

android 通过webservice方式向服务器上传图片

程序员文章站 2022-05-09 11:18:07
...

通过webservice方式向服务器上传图片

 

private Object getData(String method, Map<String, Object> map)
			throws ConnectionException {
	LogUtil.info(TAG, "URL:" + URL);
	SoapObject request = new SoapObject(NAMESPACE, method);
	if (map != null) {
		// 封装请求参数
		Set set = map.keySet();
		String str;
		for (Iterator iterator = set.iterator(); iterator.hasNext();) {
			str = (String) iterator.next();
			if (map.get(str) instanceof byte[]) {
				byte[] d = (byte[]) map.get(str);
				String data = new String(Base64.encode(d));
				request.addProperty(str,new SoapPrimitive(SoapEnvelope.ENC,"base64Binary",data));
			} else {
				request.addProperty(str, map.get(str));
			}
		}
	}
	SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
	envelope.setOutputSoapObject(request);

	envelope.bodyOut = request;
	envelope.dotNet = true;
	envelope.encodingStyle = SoapSerializationEnvelope.ENC;

	AndroidHttpTransport androidHttpTransport=new AndroidHttpTransport(URL);   
	try {
		String action = NAMESPACE + method;

		androidHttpTransport.call(action, envelope);
		return envelope.getResponse();
	} catch (Exception e) {}
}	

关键代码 :

byte[] d = (byte[]) map.get(str);
String data = new String(Base64.encode(d));
request.addProperty(str,new SoapPrimitive(SoapEnvelope.ENC,"base64Binary",data));

 

相关标签: WebService Android