Java for interface testing, this is the time to use the Java URL class and the input and output stream
Test Url:https://www.v2ex.com/api/nodes/show.json
Parameters are: Name=python
Import Java.io.bufferedreader;import Java.io.ioexception;import Java.io.inputstream;import Java.io.inputstreamreader;import Java.net.httpurlconnection;import Java.net.malformedurlexception;import Java.net.url;import Java.net.urlconnection;public class Jiekoutest {public static void main (string[] args) {TR Y {//Create URL object url url=new url ("Https://www.v2ex.com/api/nodes/show.json?name=python"); Open a URL connection and run the Client access resource. URLConnection URLConnection = (httpurlconnection) url.openconnection (); Urlconnection.connect ();//Call the Connect method provided by the URLConnection object to connect the remote service InputStream is=urlconnection.getinputstream (); /Gets the resource data accessed by the input stream//through BufferedReader to read BufferedReader buffer=new BufferedReader (New InputStreamReader (i s)); StringBuffer bs=new StringBuffer ();//store read value String l=null; The value being read is stored in StringBuffer while ((L=buffer.readline ())!=null) {bs.append (L). Append ("\ n"); } System.out.println (Bs.tostring ()); } catch (Malformedurlexception e) {e.printstacktrace (); }catch (IOException e) {e.printstacktrace (); } }}
Last obtained output
Chinese garbled problem Solving:
Set the next encoding
BufferedReader buffer=new BufferedReader (New InputStreamReader (IS, "utf-8"));
Java of interface Testing