许多JSON请求在同一连接中

时间:2015-05-14 17:58:54

标签: java json session urlconnection

我需要执行多个JSON请求,但我无法关闭当前连接

示例代码:

private String[] test(URL url, final URL url2) throws IOException {
    String[] test = new String[2];
    URLConnection openConnection = url.openConnection();
    test[0] = this.formatJSON(openConnection.getInputStream());
    url = url2;
    test[1] = this.formatJSON(openConnection.getInputStream());

    return test;
}

private String[] test(URL url, final URL url2) throws IOException {
    String[] test = new String[2];
    URLConnection openConnection = url.openConnection();
    test[0] = this.formatJSON(openConnection.getInputStream());
    url.setNewURL(url2);
    test[1] = this.formatJSON(openConnection.getInputStream());

    return test;
}

任何选项?

1 个答案:

答案 0 :(得分:0)

解决了!

要在同一会话中执行多个json请求,我只需要保存第一个的cookie,然后将其与其他人一起使用。

此链接帮助了我http://www.hccp.org/java-net-cookie-how-to.htm