Hey, I'm trying to get html from a Twitter profile page, but the httpurlconconnection is returning only a small snippet Html My code for
(int i = 0; i & lt; urls.size (); i ++) {URL URL = New URL (url.tate (I)); HttpURL Connection Connection = (HttpURL Connection) url.openConnection (); Connection.setRequestProperty ("User-agent", "Mozilla / 5.0 (Windows; U; Windows NT 6.1; N-US; RV .: 1.9.2.6) Geico / 20100625 Firefox / 3.6.6"); Println (connection.getResponseCode ()); String line; Stringbuilder builder = new stringbiller (); BufferedReader Reader = New BufferedReader (New InputStreamReader (connection.getInputStream ())); While ((line = reader. Readline ()) = null) {builder.epend (line); } String html = builder.trustring (); } I always get 200 as the response code for each call. Although around 1/3 of the time the whole HTML document is returned, and the other half only the first few hundred lines When the HTML cutoff is not always there, that amount comes back.
Any thoughts? Thanks for any help!
Additional information: After seeing the header it looks like I'm getting duplicate content-length headers. The first is the full length, the second is very small (and probably the representative of the time that I am getting some time) How can I manage duplicate headers?
This works best for me, I created one after builder.append (line) Added new line; To make it more readable in the console, but other than this, all the HTML returned for this page:
import java.io.buffferedReader; Import java.io.IOException; Import java.io.InputStreamReader; Import java.net.HttpURLConnection; Import java.net.URL; Import java.util.ArrayList; Import java.util.list; Public class HTML {Public Static Zero Main (string [] ARGS retrieves IOException throws {list & lt; string & gt; URL = new altrels & lt; string & gt; (); urls.add ("http : //stackoverflow.com/questions/3285077/java-httpurlconnection-cutting-off-html "); for (int i = 0; i & lt; urls.size (); i ++) {url url = new Url (url.at (i)); httpURL connection connection = (httpURL connection) url.openConnection (); Connection.setRequestProperty ("user-agent", "Mozilla / 5.0 (windows; u; windows NT 6.1; N-US; RV .: 1.9.2.6) Geico / 20100625 Firefox / 3.6.6 "); Println (connection.getResponseCode ()); String Line; StringBillilder Builder = New StringBuilder (); BufferedReader Reader = New BufferedReader (New InputStreamReader (connection.getInputStream ()); While ((Line = Reader. Readline ()) = Faucet (Builder.append ("\ n");} String HTML = Builder.trusting (); System.out.println ("HTML" + html);}}}
Comments
Post a Comment