使用java访问sharePoint Web服务

时间:2012-03-12 07:29:05

标签: android web-services sharepoint

    StringEntity entity = new StringEntity("<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body><Login xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\"><username>"myusername"</username><password>"mypassword"</password></Login></soap:Body></soap:Envelope>");
    entity.setContentEncoding("utf-8");

    post1.setEntity(entity);
    System.out.println("calling service");
    String response = client.execute(post, handler);

    System.out.println("response is "+response);

我得到的xml响应为:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
    <LoginResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/">
      <LoginResult>
        <ErrorCode>PasswordNotMatch</ErrorCode>
        <TimeoutSeconds>0</TimeoutSeconds>
      </LoginResult>
    </LoginResponse>
  </soap:Body>
</soap:Envelope>

请有人告诉我,我在哪里写错了?' 在此先感谢!!!

1 个答案:

答案 0 :(得分:0)

使用以下任何方法以哈希格式发送密码。但之前,请检查您的服务器是否接受散列密码,如果是,则接受哪种类型(SHA / MD5)。

SHA-256的

/**
 * Perform SHA-256 hash on the given string.
 * It returns a hashed string as Base64 string.
 * @param str String to be hashed in SHA-256
 * @return Base64 string if hashed successfully, else NULL
 */
public static String getHashSHA256(String str){
    String hash = null;

    try{
        MessageDigest digest = null;

        try { digest = MessageDigest.getInstance("SHA-256"); }
        catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            return hash;
        }

        digest.reset();
        hash = Base64.encodeToString(digest.digest(str.getBytes()),
                  Base64.DEFAULT).trim();
        digest = null;
    }
    catch (Exception e) {
        Log.e("SHA-256", "Error in getHashSHA256() due to -> " + e.toString());
    }

    return hash;
}
对于MD5

/**
 * Perform MD-5 hash on the given string.
 * It returns a hashed string as Base64 string.
 * @param str String to be hashed in MD5
 * @return Base64 string if hashed successfully, else NULL
 */
public static String getHashMD5(String str){
    String hash = null;

    try{
        MessageDigest digest = null;

        try { digest = MessageDigest.getInstance("MD5"); }
        catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            return hash;
        }

        digest.reset();
        hash = Base64.encodeToString(digest.digest(str.getBytes()),
                  Base64.DEFAULT).trim();
        digest = null;
    }
    catch (Exception e) {
        Log.e("MD5", "Error in getHashMD5() due to -> " + e.toString());
    }

    return hash;
}