getResponseCode = 404仅限此站点

时间:2018-02-08 16:26:21

标签: android xml-parsing rss httpurlconnection

我的代码适用于任何RSS提要,如BBC和fakeapi以及sciencemag等。 ..但我试图使用fifa.com的RSS feed和ResponseCode结果总是= 404

我现在要做什么,请???  这是我的连接代码

//String address ="http://www.sciencemag.org/rss/news_current.xml";//worked
//   String address = "http://feeds.bbci.co.uk/news/world/rss.xml";// worked

String address =“http://www.fifa.com/rss/index.xml”; // 404错误代码

public Document httpconnection() {
    try {

        url = new URL(address);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("GET");
        int responseCode = connection.getResponseCode();
        Log.e("TAG", "connection.getResponseCode()" + a);
        InputStream inputStream = connection.getInputStream();
        DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();

        DocumentBuilder builder = builderFactory.newDocumentBuilder();
        Document xmlDoc = builder.parse(inputStream);

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

提前致谢

0 个答案:

没有答案