Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/398.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 同一连接中的多个JSON请求_Java_Json_Session_Urlconnection - Fatal编程技术网

Java 同一连接中的多个JSON请求

Java 同一连接中的多个JSON请求,java,json,session,urlconnection,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(

我需要执行多个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;
}

有什么选择吗?

解决了

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


这个链接帮助了我

格式化JSON方法的作用是什么?你在读inputStream的所有可用输入吗?我已经解决了这个问题,
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;
}