1

これは簡単かもしれませんが、私は混乱しています。

Android Restlet を使用してサーバー上で HTTP POST を実行しようとしており、サーバーから返された応答を読み取ろうとしています。

私は以下を使用してフォームを作成しました:

Form form = new Form
form.add("msg" ,"This is my message");

今、私は次のように clientResource を持っています:

ClientResource clientResource = new ClientResource("www.example.com/my-http-post-url/");

今、私は HTTP Post を次のようにやっています:

Representation response=null;

try{

 response= clientResource.post(form.getWebRepresentation(null));
 System.out.println("Got response !! , response : " + response.getText());
 System.out.println( "Got Context: " + clientResource.getContext() );
 System.out.println( "Got Response: " + clientResource.getResponse());
 System.out.println( "Got Resonse Attribute : " + clientResource.getResponseAttributes() );
 System.out.println( "Got Resonse Entity: " + clientResource.getResponseEntity() );

}catch(Exception e){

e.printStackTrace();

}

コードが try 内にあることがわかりましたが、その印刷は次のとおりです。

I/org.restlet(  493): Starting the default HTTP client
I/System.out(  493): Got response !! , response : null
I/System.out(  493): Got Context: null
I/System.out(  493): Got Response: HTTP/1.1 - OK (200) - OK
I/System.out(  493): Got Resonse Attribute : {org.restlet.http.headers=[(Date,Sun, 22 Jul 2012 22:14:03 GMT), (Server,WSGIServer/0.1 Python/2.7.1+), (Vary,Authorization), (Content-Type,application/json; charset=utf-8)]}
I/System.out(  493): Got Resonse Entity: [application/json,UTF-8]

サーバーが応答しているかどうかを確認するためにデータを盗聴してみましたが、サーバーが応答コンテンツを送信していると確信しています。

サーバーから送信された応答コンテンツを見つけるにはどうすればよいですか?

4

2 に答える 2

0

Restlet のクライアント側サポートを正しい方法で使用しています。応答コンテンツは、応答表現内に含まれている必要があります...

最初のステップは、Android の外部で REST サービスを呼び出して、正確な応答コンテンツを確認することです。restclient (http://code.google.com/p/rest-client/) または curl を使用してこれを実行できますか?

ティエリー

于 2012-07-23T14:56:54.320 に答える
0

次のようなことを試してください:

私は今これに似たものを持っています:

ClientResource clientResource = new ClientResource(url);
Request request = new Request(Method.POST, url);

clientResource.setRequest(request);

    Form form = new Form();

    form.set("foo", "barValue");

    org.restlet.representation.Representation   response = clientResource.post(form, MediaType.APPLICATION_JSON);
    Representation responseEntity = clientResource.getResponseEntity();

    JsonRepresentation jsonRepresentation = new JsonRepresentation(responseEntity);

    JSONObject jsonObject = jsonRepresentation.getJsonObject();
    String[] names = JSONObject.getNames(jsonObject);

    if (jsonObject.has("errorString"))
    {
        String error = jsonObject.optString("errorString");
    }
于 2014-12-22T18:02:39.927 に答える