認証を要求するwebserviceに接続する必要があります。 Iヘッダーを使用しようとした: 7月25日14:03:20.922:KSOAP2経由でHTTP認証SOAP WebサービスにアクセスするHttpTransportBasicAuth
Element usernameElement = new Element().createElement(NAMESPACE, "Username");
usernameElement.addChild(Node.TEXT, "user");
Element passwordElement = new Element().createElement(NAMESPACE, "Password");
passwordElement.addChild(Node.TEXT, "pass");
Element header = new Element().createElement(NAMESPACE, "AuthHeader");
header.addChild(Node.ELEMENT, usernameElement);
header.addChild(Node.ELEMENT, passwordElement);
soapEnvelope.headerOut= new Element[]{header};
Iがエラーを受け取る(584)/ System.errのに警告:org.xmlpull.v1.XmlPullParserException:期待:START_TAG { }エンベロープ(位置:START_TAG @ 1:6 in [email protected])
ウェブサービスはHTML形式のエラーを返していますが、どのように表示されますか?そのようなリクエストのtextview.settext()を作成することも、LogCatに出力することもできますか?どのように私はそれを作ることができますし、私はそれを受信していますか:(
私は、HttpTransportBasicAuthクラスを使用しようとしました - それは仕事にするために多くの問題に直面した - 私は、 HttpTransportからHttpTransportSEへとServiceConnectionMIDPからServiceConnectionSEにksoap2・アンドロイド・アセンブリ-2.5.7でこのようなクラスがありませんでしたので、最後にそれがエラーなしでコンパイル:。
package com.android.testinet;
import org.ksoap2.transport.*;
import org.ksoap2.transport.HttpTransportSE;
import java.io.*;
public class HttpTransportBasicAuth extends HttpTransportSE {
private String username;
private String password;
/**
* Constructor with username and password
*
* @param url
* The url address of the webservice endpoint
* @param username
* Username for the Basic Authentication challenge RFC 2617
* @param password
* Password for the Basic Authentication challenge RFC 2617
*/
public HttpTransportBasicAuth(String url, String username, String password) {
super(url);
this.username = username;
this.password = password;
}
protected ServiceConnection getServiceConnection() throws IOException {
ServiceConnectionSE midpConnection = new ServiceConnectionSE(url);
addBasicAuthentication(midpConnection);
return midpConnection;
}
protected void addBasicAuthentication(ServiceConnection midpConnection) throws IOException {
if (username != null && password != null) {
StringBuffer buf = new StringBuffer(username);
buf.append(':').append(password);
byte[] raw = buf.toString().getBytes();
buf.setLength(0);
buf.append("Basic ");
org.kobjects.base64.Base64.encode(raw, 0, raw.length, buf);
midpConnection.setRequestProperty("Authorization", buf.toString());
}
}
} それはHttpTransportBasicAuthで今okです.callメソッドはエラーがないので、私はまだエラーを受け取ります: 07-25 14:03:20.922:WARN/System.err(584):org.xmlpull.v1.XmlPullParserException:予想される:START_TAG {http://schemas.xmlsoap.org/soap/envelope/}プロジェクトを実行するとエンベロープ(位置:START_TAG @ 1:6 in [email protected]) は、ここで私はWebサービスに接続しようとしたことにより、私のコードです:
HttpTransportBasicAuth aht= new HttpTransportBasicAuth(URL, "user", "pass");
try
{
aht.call(SOAP_ACTION, soapEnvelope);
SoapPrimitive tmp_ResultString = (SoapPrimitive) soapEnvelope.getResponse();
ResultString = tmp_ResultString.toString();
// tv.setText(ResultString);
}
catch(Exception e)
{
e.printStackTrace();
}
そして最後に、私はこのソースを使用してみました: Webservice Http Authentication - KSOAP2 on Android が、コンパイラをHeaderPropertyが何であるかを知りません。私はそれを大丈夫にするために何をインポートすべきですか? LogCatでエラーが発生しているため、正確なエラーメッセージwebserviceがタグで返す内容を確認する方法を教えてください。おかげさまで