HTTP request for XML file

后端 未结 2 797
礼貌的吻别
礼貌的吻别 2020-12-05 20:04

I\'m trying to use Flurry Analytics for my program on Android and I\'m having trouble getting the xml file itself from the server.

I\'m getting close because in the

2条回答
  •  天涯浪人
    2020-12-05 20:18

    The parse method that takes a string is for a URL format. You need to wrap the String in a StringReader before parsing it. It is even better if you can grab the XML as an InputStream and parse that, something like:

    String uri =
        "http://api.flurry.com/eventMetrics/Event?apiAccessCode=?????&apiKey=??????&startDate=2011-2-28&endDate=2011-3-1&eventName=Tip%20Calculated";
    
    URL url = new URL(uri);
    HttpURLConnection connection =
        (HttpURLConnection) url.openConnection();
    connection.setRequestMethod("GET");
    connection.setRequestProperty("Accept", "application/xml");
    
    InputStream xml = connection.getInputStream();
    
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document doc = db.parse(xml);
    

提交回复
热议问题