Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java HTTPResponse';游戏中的字符串为空_Java_Android_Playframework - Fatal编程技术网

Java HTTPResponse';游戏中的字符串为空

Java HTTPResponse';游戏中的字符串为空,java,android,playframework,Java,Android,Playframework,我在服务器上使用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); // pr

我在服务器上使用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");
   }
}
公共静态结果广播(字符串频道、字符串消息)
{
尝试
{
FayeClient faye=新的FayeClient(“本地主机”);
int code=faye.send(通道、消息);
//打印代码(打印200)。

返回ok(“Hello”);使用诸如Fiddler之类的工具,查看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)
{
  // ...
}