Page static-http Get request get page content code

Source: Internet
Author: User
Tags httpcontext

1 Importorg.apache.http.HttpEntity;2 Importorg.apache.http.HttpException;3 ImportOrg.apache.http.HttpResponse;4 Importorg.apache.http.client.HttpClient;5 ImportOrg.apache.http.client.methods.HttpGet;6 Importorg.apache.http.client.methods.HttpRequestBase;7 Importorg.apache.http.impl.client.HttpClients;8 ImportOrg.apache.http.protocol.BasicHttpContext;9 ImportOrg.apache.http.protocol.HttpContext;Ten Importorg.apache.http.util.EntityUtils; One  A /** - * page static, get page content via HTTP GET request - * Note: To introduce common-logging, Httpcore, httpclient jar packages the  */ -  Public classpagestatic - { -      Public Static voidMain (string[] args) +     { -HttpClient client =Httpclients.createdefault (); +String url = "http://fanyi.youdao.com/"; AHttprequestbase http =Newhttpget (URL); atHttpContext context =NewBasichttpcontext (); -         Try -         { -HttpResponse response =Client.execute (HTTP, context); -             intStatusCode =response.getstatusline (). Getstatuscode (); -  in             Switch(StatusCode) -             { to                  Case200: +                  Case400://Business Exception -                      Break; the                 default: *                     Throw NewHttpException (url + "Status Code:" +statusCode); $             }Panax Notoginseng  -httpentity entity =response.getentity (); theString restr =entityutils.tostring (entity); + System.out.println (RESTR); A         } the         Catch(Exception e) +         { - System.out.println (e.tostring ()); $         } $     } -  -}
View Code

Page static-http Get request get page content code

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.