0

このリンクを使用して webservice を呼び出したアプリケーションがあります。1 つの webservice URL があり、別の Url がその URL からの応答として取得されます。その URL を次のように使用する必要があります。

public static final String TIME_CENTRAL_SERVER = " http://accounts.myexample.com/Services "; 「 http://accounts.myexample.com/Services 」の代わりに、json 応答を解析する必要があります。

Google で確認しましたが、回答が得られませんでした。質問がある場合は、私に聞いてください。

4

2 に答える 2

0

最初の Web サービス呼び出しは以下のようになります

RestClient client = new RestClient(LOGIN_URL);
client.AddParam("accountType", "GOOGLE");
client.AddParam("source", "tboda-widgalytics-0.1");
client.AddParam("Email", _username);
client.AddParam("Passwd", _password);
client.AddParam("service", "analytics");
client.AddHeader("GData-Version", "2");

try {
    client.Execute(RequestMethod.POST);
} catch (Exception e) {
    e.printStackTrace();
}

String response = client.getResponse();

応答を解析した後、別の Web サービス呼び出しを実行する場合は、別の URL とパラメーターを使用して RestClient の別のオブジェクトを作成し、以下のように execute メソッドを呼び出します。

RestClient client1 = new RestClient(GET_INFO_URL);
client1.AddParam("userid", "123");

try {
    client1.Execute(RequestMethod.POST);
} catch (Exception e) {
    e.printStackTrace();
}

String response1 = client1.getResponse();
于 2013-03-29T11:52:55.503 に答える
0

最後に、チームヘッドのガイダンスで問題を解決しました。以下は、constants.java クラスで使用したコードです。

public static final String GET_CENTRAL_SERVER = String.format("%s/AccountService/security/ValidateAccess", TIMEMACHINE_ACCOUNTS_SERVER);

serversync.java クラスにコード スニペットを追加します。

public String getCentralServer(Context context, String serial_number) throws Exception{
    // TODO Auto-generated method stub
    WebServiceClient client = new WebServiceClient(Constants.GET_CENTRAL_SERVER);
    client.addParam("accesscode", String.valueOf(serial_number));
    client.addParam("type", "2");
    client.Execute(RequestMethod.GET);
    String response = client.getResponse();
    if (response != null){
        response = response.replaceAll("\\\\/", "/");
        response = response.replace("\"", "");
        response = response.replace("\n","");
        response = "http://" + response;
        return response;
    }

    return null;
}
于 2013-04-01T09:44:25.493 に答える