java - Read XML from valid URL not returned. Header formatting issue? -
java - Read XML from valid URL not returned. Header formatting issue? -
i trying utilize code below read valid url. can re-create , paste url browser , works (displays xml) when seek access programatically returns nil (no info , no error). have tried set user-agent via post: can't read in html content valid url didnt prepare problem. if matters trying single eve api call. believe problem not have headers formatted correctly, , eve site rejecting query. can access info fine using php, had alter languages.
public static void readfiletoxml(string urlstring,string fname) { try{ java.net.url url = new java.net.url(urlstring); system.out.println(url); urlconnection cnx = url.openconnection(); cnx.setallowuserinteraction(false); cnx.setdooutput(true); cnx.addrequestproperty("user-agent", "mozilla/5.0 (windows; u; windows nt 5.1; en-us) applewebkit/531.0 (khtml, gecko) chrome/3.0.183.1 safari/531.0"); system.out.println(cnx.getcontentlengthlong());// alter suggested in comments. returns -1 inputstream = cnx.getinputstream(); bufferedreader br = new bufferedreader(new inputstreamreader(is)); file file=new file("c:\\users\\xxx\\desktop\\"+fname); bufferedwriter bw = new bufferedwriter(new filewriter(file,false)); string inputline; while ((inputline = br.readline()) != null) { bw.write(inputline); system.out.println(inputline); } system.out.println("finished read"); bw.close(); br.close(); } catch(exception e) { system.out.println("exception: "+e.getmessage()); } }
java url file-io http-headers
Comments
Post a Comment