Directly attach the code, copy runs directly
Package com.sh.browser;import java.io.bufferedreader;import java.io.fileoutputstream;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.io.outputstreamwriter;import java.io.printwriter;import java.net.url;import java.net.urlconnection;public class getpagecontent { /** * @param Args */ public static void main (String[] args) { try { //http://api.map.baidu.com/geocoder/v2/?ak=kqipaektt6xaorkmbmlvbzze&callback= renderreverse&location=31.249161,121.487899&output=json&pois=1&qq-pf-to=pcqq.c2c url u1=new url ("http://api.map.baidu.com/location/ip?ak=E4805d16520de693a3fe707cdc962045 &ip=202.198.16.3&coor=bd09ll "); url url = new url ("Http://api.Map.baidu.com/location/ip?ak=e4805d16520de693a3fe707cdc962045&ip=183.56.167.29&coor=bd09ll "); urlconnection conn = url.openconnection (); conn.setdooutput (True); inputstream in = null; in = url.openstream (); string content = pipe (In, "Utf-8"); system.out.println (content); } catch (exception e) { E.printstacktrace (); } } static string pipe (inputstream in,string CharSet) throws IOException { StringBuffer S = new stringbuffer (); if (charset==null| | "". Equals (CharSet)) { charset= "Utf-8"; } String rLine = null; bufferedreader breader = new bufferedreader (New InputStreamReader ( In,charset)); printwriter pw = null; fileoutputstream fo = new fileoutputstream (".. /index.html "); outputstreamwriter writer = new outputstreamwriter (fo, " Utf-8 "); pw = new printwriter (writer); while ( (Rline = breader.readline ()) != null) { String tmp_rLine = rLine; int str_len = tmp_rline.length (); if (str_len > 0) { s.append (Tmp_rline); pw.println (Tmp_rline); pw.flush (); } tmp_ rline = null; } in.close (); pw.close (); return s.tostring (); }}
Java obtains web page source code and simulates browser request