吗买比。。。。。。
在这记录一个天大的坑。。。。。这个坑掉进去好几天!!
Android下对接WebServer,啥??WebServer?我的第一反应是这货用C#写的,因为我之前有写过。。所以开始在网上找方法,。。。中间搞了几天,发觉对方一直说收不到我传过去的值,简直是超(ri)感(le)动(gou)。也中间写了.net的接口访问,访问并没什么问题,中间找了很多种方法。在网上找到了一个东西axis2。。。的因为安卓下并不能用axis2(这货依赖的rmi等包在安卓下无法使用),最终在eclipse下用axis2去写才能正常访问,通过抓包拿到了真正的访问数据。
下面把关键技术记录如下,记录这个踩过的坑,也能帮助需要的人...
Android下请求JAVA写的WebServer接口方法
仿照访问对接.net接口的形式,只是封装成的东西不一样(其实就是这么简单),用java普通的网络访问即可完成,完整代码如下。
/**
* 对接Java写的WebServer,封装成的数据格式如下
*
* <?xml version='1.0' encoding='UTF-8'?>
* <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
* <soapenv:Body>
* <{methodName} xmlns="{namespace}">
* <arg0 xmlns="">xxx</arg0>
* <arg1 xmlns="">xxx</arg1>
* <arg2 xmlns="">xxx</arg2>
* </{methodName}>
* </soapenv:Body>
* </soapenv:Envelope>
*
*
* @param params
* @param _url
* @param namespace
* @param methodName
* @return
*/
public static String doRequest2(Map<String, String> params, String _url, String namespace, String methodName) {
String str = "";
try {
URL url = new URL(_url);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setDoOutput(true);
con.setDoInput(true);
con.setRequestProperty("User-Agent", "Axis2");
con.setRequestProperty("SOAPAction", "");
con.setRequestProperty("Content-Type", "text/xml; charset=UTF-8");
con.connect();
OutputStreamWriter out = new OutputStreamWriter(c