Java 发送多个Get请求

Java 发送多个Get请求,java,get,Java,Get,我正在编写代码来发送获取URL列表的请求。现在,一些get请求失败,并且没有返回HTTP响应代码200。但是当我点击浏览器上get请求的URL时,我就能够下载XML文件(这就是应该发生的事情)。我的第一个问题是,当我从代码发送get请求时,为什么会发生这种情况,请求失败,但在其他情况下不会失败 我的第二个问题是如何解决get请求失败的问题 请在下面找到我在代码中编写的代码示例 URL obj = new URL(url); HttpURLConnection con =

我正在编写代码来发送获取URL列表的请求。现在,一些get请求失败,并且没有返回HTTP响应代码200。但是当我点击浏览器上get请求的URL时,我就能够下载XML文件(这就是应该发生的事情)。我的第一个问题是,当我从代码发送get请求时,为什么会发生这种情况,请求失败,但在其他情况下不会失败

我的第二个问题是如何解决get请求失败的问题

请在下面找到我在代码中编写的代码示例

URL obj = new URL(url);
            HttpURLConnection con = (HttpURLConnection) obj.openConnection();

            // optional default is GET
            con.setRequestMethod("GET");

            //add request header
            con.setRequestProperty("User-Agent", USER_AGENT);

            int responseCode = con.getResponseCode();
            System.out.println("\nSending 'GET' request to URL : " + url);
            System.out.println("Response Code : " + responseCode);

            BufferedReader in = new BufferedReader(
                    new InputStreamReader(con.getInputStream()));
            String inputLine;
            StringBuffer response = new StringBuffer();

            while ((inputLine = in.readLine()) != null) {
                response.append(inputLine);
            }
            in.close();
例外情况是:

Update:
Response Code : 404
java.io.FileNotFoundException: http://gdata.youtube.com/feeds/api/videos/gzakooXyvuA
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection$6.run(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection$6.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.net.www.protocol.http.HttpURLConnection.getChainedException(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
    at ReadMyExcel.sendGet(ReadMyExcel.java:133)
    at ReadMyExcel.readExcel(ReadMyExcel.java:82)
    at ReadMyExcel.main(ReadMyExcel.java:99)

我认为只有使用OAuth2对Google进行身份验证,这才有效。我曾尝试从浏览器访问url,但收到了相同的404错误消息

您可能正在尝试访问仅限于您的用户帐户的提要


使用和检查以了解如何对Youtube API进行身份验证和发出请求。

当代码发出get请求时,您会得到什么HTTP状态代码的响应?如果不是200秒,将返回什么响应代码?同时发布程序的调试输出。您是否尝试在浏览器中点击该URL?猜猜返回了什么代码?是的,我试着在浏览器中点击url。返回xml。