android调用webservice发送header身份验证不成功

移动开发 码拜 9年前 (2015-04-24) 2065次浏览 0个评论

我的代码
SoapObject request = new SoapObject(
“http://webservices.home.whot.com”, “getVoteImgPath”);
String namespace = “http://webservices.home.whot.com”;
Element[] header = new Element[1];
header[0] = new Element().createElement(namespace,
“authenticationtoken”);

// Element userName = new Element().createElement(namespace, “username”);
// userName.addChild(Node.TEXT, “q1101876746”);
// header[0].addChild(Node.ELEMENT, userName);
//
// Element pass = new Element().createElement(namespace, “password”);
// pass.addChild(Node.TEXT, “252931024”);
// header[0].addChild(Node.ELEMENT, pass);

header[0].setAttribute(namespace, “username”, “q1101876746”);
header[0].setAttribute(namespace, “password”, “252931024”);

//<soap:Header><authenticationtoken><username>abcd</username><password>34</password></authenticationtoken></soap:Header>
request.addProperty(“id”, 163);

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.headerOut = header;
envelope.bodyOut = request;
envelope.dotNet = true;
// envelope.setOutputSoapObject(request);

HttpTransportSE ht = new HttpTransportSE(
“http://test.rank365.cn/open/services/StartVotes”);
ht.debug = true;
try {
long start = System.currentTimeMillis();
ht.call(null, envelope);
long timeNum = System.currentTimeMillis() – start;

Log.i(“SoapService”, “callService时长:” + timeNum);
// Object bodyIn = envelope.bodyIn;
Object response = envelope.getResponse();
// Object response = envelope.bodyIn;
if (response != null) {
// String str = JsonUtils.object2Json(response);
// System.out.println(str);
System.out.println(response.toString()+”————-“);
System.out.println(ht.requestDump);
System.out.println(“—————————–“);
System.out.println(ht.responseDump);
return response;
} else {
// TODO 其他情况处理
}
} catch (Exception e) {
e.printStackTrace();
System.out.println(ht.requestDump);
if (handler != null) {
Message msg = handler.obtainMessage();
// msg.what = Constants.HANDLER_WHAT_EXCEPTION;
msg.obj = “连接服务器连接异常”;
handler.sendMessage(msg);
}
}

 

return null;

android调用webservice发送header身份验证不成功
<v:Envelope xmlns:i=”http://www.w3.org/2001/XMLSchema-instance” xmlns:d=”http://www.w3.org/2001/XMLSchema” xmlns:c=”http://schemas.xmlsoap.org/soap/encoding/” xmlns:v=”http://schemas.xmlsoap.org/soap/envelope/”><v:Header><n0:authenticationtoken n0:username=”q1101876746″ n0:password=”252931024″ xmlns:n0=”http://webservices.home.whot.com” /></v:Header><v:Body><getVoteImgPath xmlns=”http://webservices.home.whot.com” id=”o0″ c:root=”1″><id i:type=”d:int”>163</id></getVoteImgPath></v:Body></v:Envelope>

而且标签里面都是v ,而不是soap ,请求一直不成功,大神帮忙看看什么问题,困扰要几天了

android调用webservice发送header身份验证不成功
给自己顶一下,非常期待大神啊,头疼死了
android调用webservice发送header身份验证不成功
在线等啊
android调用webservice发送header身份验证不成功
20分
没接触过,帮你顶吧
android调用webservice发送header身份验证不成功
可算是有人帮忙顶一下了,继续等待大神啊
android调用webservice发送header身份验证不成功
80分
http://stackoverflow.com/questions/11179610/customization-of-ksoap2-android-envelope这个问题和你一样的
android调用webservice发送header身份验证不成功
对我确实有点用,可是没解决啊,而且这个v应该是ksoap自己封装好的。服务器那边他们写的时候是根据soap:这样的标签取得的数据,我想让他们判断一下,如果是android传过去的数据根据v:取数据,应该就可以了吧,不知道可行不可行,中午跟服务那边商量一下
android调用webservice发送header身份验证不成功
还有没人帮忙一下啊,今天下午吧ksoap2的jar包给反编译过来了,里面有的class就是加的v,我想改成soap然后重新引用,可惜一直出错,jar包不能用了。在此求救了,如果还没有方法的话我就要结贴啦。
android调用webservice发送header身份验证不成功
对了,问题,解决了,把头部验证那一段代码改成这样就可以了
SoapObject request = new SoapObject(“http://webservices.home.whot.com”,
“getVoteOptions”);
Element[] header = new Element[1];
header[0] = new Element();
header[0].setName(“authenticationtoken”);

Element userName = new Element();
userName.setName(“username”);
userName.addChild(Node.TEXT, “q1101876746”);
header[0].addChild(Node.ELEMENT, userName);

Element pass = new Element();
pass.setName(“password”);
pass.addChild(Node.TEXT, “252931024”);
header[0].addChild(Node.ELEMENT, pass);
—————————————————————————————————————————————–
原来了面把标签多加了好几个无用的标签,服务那边解析不了,这样写的话就不会多无用的标签了,反正解决了,现在才贴出解决的方法,大家可以试下

android调用webservice发送header身份验证不成功
引用 9 楼 q1101876746 的回复:

对了,问题,解决了,把头部验证那一段代码改成这样就可以了
SoapObject request = new SoapObject(“http://webservices.home.whot.com”,
“getVoteOptions”);
Element[] header = new Element[1];
header[0] = new Element();
header[0].setName(“authenticationtoken”);

Element userName = new Element();
userName.setName(“username”);
userName.addChild(Node.TEXT, “q1101876746”);
header[0].addChild(Node.ELEMENT, userName);

Element pass = new Element();
pass.setName(“password”);
pass.addChild(Node.TEXT, “252931024”);
header[0].addChild(Node.ELEMENT, pass);
—————————————————————————————————————————————–
原来了面把标签多加了好几个无用的标签,服务那边解析不了,这样写的话就不会多无用的标签了,反正解决了,现在才贴出解决的方法,大家可以试下

我最近也在为这个问题烦恼,安卓要调用服务器添加了cxf 认证的webservice接口,总是提示访问不到服务器地址。楼主能指教下吗? 谢谢。

android调用webservice发送header身份验证不成功
楼主可否将代码共享与我,小弟也为此头疼中
android调用webservice发送header身份验证不成功
哎 头痛啊

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明android调用webservice发送header身份验证不成功
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!