码迷,mamicode.com
首页 > 移动开发 > 详细

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

时间:2014-10-20 22:51:50      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:android   blog   http   io   os   ar   java   sp   2014   

============问题描述============


我的代码
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============


没接触过,帮你顶吧bubuko.com,布布扣

============解决方案2============


http://stackoverflow.com/questions/11179610/customization-of-ksoap2-android-envelope这个问题和你一样的

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

标签:android   blog   http   io   os   ar   java   sp   2014   

原文地址:http://www.cnblogs.com/liangxieliang56/p/4038805.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!