0

サーバーで Play と Faye を使用しています。Play は API 呼び出しに使用され、Faye はクライアントとの通信に使用されます。

だから、私はサーバーにこのメソッドを持っています:

public static Result broadcast(String channel, String message)
{
   try
   {
       FayeClient faye = new FayeClient("localhost");
       int code = faye.send(channel, message);
       // print the code (prints 200).

       return ok("Hello"); <------------ This is what we care about.
   }
   catch(Exception e)
   {
      return ok("false");
   }
}

これは、Android フォンであるclientのコードです。(これは、サーバーに何かを送信して応答を返す HTTP ポスト メソッドです 。問題は、応答のメッセージを出力できないことです。

public static String post(String url, List<BasicNameValuePair> params)
{

    HttpClient httpclient = new DefaultHttpClient();
    String result = "";
    // Prepare a request object
    HttpPost httpPost;
    httpPost = new HttpPost(url);
    httpPost.setHeader("Content-type", "application/json");
    httpPost.setHeader("Accept", "application/json");

    JSONObject obj = new JSONObject();

    try
    {
        for (NameValuePair pair : params)
            obj.put(pair.getName(), pair.getValue());
    }
    catch (JSONException e)
    {
        return e.getMessage();
    }
    // Add your data
    try
    {
        httpPost.setEntity(new StringEntity(obj.toString(), "UTF-8"));
    }
    catch (UnsupportedEncodingException e)
    {
        return e.getMessage();
    }
HttpResponse httpResponse;
        try
        {
            httpResponse = httpclient.execute(httpPost);


            // Get hold of the response entity
            HttpEntity entity = httpResponse.getEntity();

            String str = EntityUtils.toString(entity);
            Log.e("RestClient", "result = \"" + str + "\""); // hello should be printed here??
}
catch(Exception e)
{
  // ...
}

問題は、logcat で出力されるのが [result = ""] であることです。私は何か間違ったことをしていますか?ありがとうございました。

4

1 に答える 1