您的位置:首页 > 移动开发 > Android开发

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

2017-01-01 00:20 465 查看
我的代码

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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: