zoukankan      html  css  js  c++  java
  • 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这个问题和你一样的
  • 相关阅读:
    Strust2学习笔记
    EL与OGNL区别
    十进制与其他进制转换
    JSTL
    <jsp:include>和<%@include%>区别
    AngularJS 内置过滤器
    ubuntu下swift安装
    ubuntu下gerrit 安装部署
    java日期操作
    SpringMVC GET请求中文数据传递到Server端乱码
  • 原文地址:https://www.cnblogs.com/lianxu61/p/4002037.html
Copyright © 2011-2022 走看看