首页 > 代码库 > android调用webservice发送header身份验证不成功
android调用webservice发送header身份验证不成功
====================问题描述====================
我的代码
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;
====================解决方案1====================
没接触过,帮你顶吧
====================解决方案2====================
http://stackoverflow.com/questions/11179610/customization-of-ksoap2-android-envelope这个问题和你一样的
android调用webservice发送header身份验证不成功
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。