Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/348.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
从URL加载API时FileNotFoundException。JAVA安卓_Java_Android_Json_Api_Android Studio - Fatal编程技术网

从URL加载API时FileNotFoundException。JAVA安卓

从URL加载API时FileNotFoundException。JAVA安卓,java,android,json,api,android-studio,Java,Android,Json,Api,Android Studio,我正在尝试从此api返回JSON字符串: 但是Java抛出了错误: java.io.FileNotFoundException: https://pareshchouhan-trivia-v1.p.mashape.com/v1/getAllQuizQuestions?limit=10&page=1 在线 br = new BufferedReader(new InputStreamReader(connection.getInputStream())); 我在其他RESTAPI中使

我正在尝试从此api返回JSON字符串:

但是Java抛出了错误:

java.io.FileNotFoundException: https://pareshchouhan-trivia-v1.p.mashape.com/v1/getAllQuizQuestions?limit=10&page=1
在线

br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
我在其他RESTAPI中使用了类似的代码,所以我有点不确定为什么会发生这种情况

    static String jsonStr;
    String data = "";


    @Override
    protected Void doInBackground(Void... params) {
        BufferedReader br = null;


        try {

            URL url;
            String urlStr = "https://pareshchouhan-trivia-v1.p.mashape.com/v1/getAllQuizQuestions?limit=10&page=1";
            url = new URL(urlStr);

            URLConnection connection = url.openConnection();
            connection.setRequestProperty("X-Mashape-Key", "4OFryNEYTWmshe8GheSnmIVEj7gZp1kJf6cjsncjVhXj9WYACn");
            connection.setRequestProperty("Accept", "application/json");
            connection.setDoOutput(true);

            OutputStreamWriter outputStreamWr = new OutputStreamWriter(connection.getOutputStream());
            outputStreamWr.write(data);
            outputStreamWr.flush();



            br = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            StringBuilder sb = new StringBuilder();
            String line = null;

            while((line = br.readLine())!=null) {
                sb.append(line);
                sb.append(System.getProperty("line.separator"));
            }

            jsonStr = sb.toString();


        } catch (Exception e){
            e.printStackTrace();
        }
        return null;

    }
任何帮助都将不胜感激。
问候。

原来我试图执行错误类型的请求。此特定API不支持Get请求。发现这个

无论如何,使用此处提供的教程: 我能够更改请求类型并提取正确的数据


希望这能有所帮助。

结果表明我试图执行错误类型的请求。此特定API不支持Get请求。发现这个

无论如何,使用此处提供的教程: 我能够更改请求类型并提取正确的数据

希望这有帮助