Java of interface Testing

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.