2

KSOAP2基本認証で使用しようとしています。私はダウンロードしていますksoap2-android-assembly-3.0.0-jar-with-dependencies.jar、、。以下のコードを使用しようとしました:ksoap2-extras-3.0.0.jarksoap2-extra-ntlm-3.0.0.jar

ArrayList<HeaderProperty> headerProperty = new ArrayList<HeaderProperty>();
headerProperty.add(new HeaderProperty("Authorization", "Basic " + 
org.kobjects.base64.Base64.encode("user:password".getBytes())));

それはエラーを生成します:

java.io.IOException: HTTP request failed, HTTP status: 401
ERROR:java.io.IOException:HTTP request failed, HTTP status: 401

私も以下のコードを使用しようとしました:

HttpTransportBasicAuth androidHttpTpAut = new HttpTransportBasicAuth(URL, "user", "password");
androidHttpTpAut.getServiceConnection().connect();

再び機能しない場合、エラーが発生します。

Exception in thread "main" java.lang.NoClassDefFoundError: org/ksoap2/transport/HttpTransport
    at java.lang.ClassLoader.defineClass1(Native Method)

誰でもこの作業はうまくいきますか?

4

2 に答える 2

4

多くのテストの後、以下のコードを変更する必要があることがわかりました。

ArrayList headerProperty = new ArrayList();
headerProperty.add(new HeaderProperty("Authorization", "Basic " +
org.kobjects.base64.Base64.encode("user:password".getBytes())));

androidHttpTransport.call(SOAP_ACTION, envelope);

androidHttpTransport.call()上記のポリモーフィック メソッドを以下に変更します。

androidHttpTransport.call(SOAP_ACTION, envelope, headerProperty);

headerPropertyパラメータを methodに入れる必要がありますandroidHttpTransport.call。そして、私ksoap2-android-assembly-3.0.0-jar-with-dependencies.jarはプロジェクトでのみ使用します。

ありがとう

于 2013-06-30T16:44:00.677 に答える