如何打印以从java中的json + http帖子中筛选返回的字符串

时间:2014-12-13 09:58:28

标签: java json apache http nginx

我正在java中创建一个json + http帖子。如果http帖子成功,我应该有一个唯一的标识符字符串从端点/服务器返回给我。到目前为止,我的帖子很成功,但我不知道如何在屏幕上打印这个唯一标识符。

以下是我运行程序时得到的输出;

HttpResponseProxy{HTTP/1.1 200 OK [Server: nginx/1.6.2, Date: Sat, 13 Dec 2014 09:03:41 GMT, Content-Type: application/json; charset=utf-8, Content-Length: 24, Connection: keep-alive, Access-Control-Allow-Methods: *, Access-Control-Allow-Origin: *, X-Parse-Platform: G1, X-Runtime: 0.166030] ResponseEntityProxy{[Content-Type: application/json; charset=utf-8,Content-Length: 24,Chunked: false]}}

如何将返回对象打印到屏幕?

编辑:

这是我的代码;     //导入库

public class XXXXXXXX {


    public static void main(String[] args ) throws IOException {
    // TODO Auto-generated method stub

        Registration ifeanyi = new Registration();
        String endPoint = "http://xxxxxxxxxxx/api/register";
        HttpPost post = new HttpPost(endPoint); 
        GsonBuilder builder = new GsonBuilder();
        Gson gson = builder.create();

        ifeanyi.email = "xxxxxxxxxxx@yahoo.com";
        ifeanyi.github = "https://xxxxxxxxxxx/code2040Challenge.git";

        CloseableHttpClient httpclient = HttpClients.createDefault();

        try {               
            StringEntity data = new StringEntity(gson.toJson(ifeanyi));
            post.setEntity(data);
            post.setHeader("Content-type", "application/json");
            HttpResponse result = httpclient.execute(post);
            HttpEntity entity = result.getEntity();
            System.out.println(result);
            System.out.println(post);
        } catch (Exception handle) {
        // TODO Auto-generated catch block
            handle.printStackTrace();           
        } finally {
            httpclient.close();
        }   
    }
}

0 个答案:

没有答案