android調用webservice發送header身分識別驗證不成功

來源:互聯網
上載者:User

標籤:android   blog   http   io   ar   os   java   sp   on   

============問題描述============


My Code
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個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.