Java the simplest way to implement HttpGet and HttpPost requests

Source: Internet
Author: User

Java implements HttpGet and HttpPost requests in a variety of ways, a personal summary of the simplest way, just a few lines of code, can be perfectly implemented.

Here need to use two jar package, Httpclient-4.3.1.jar, Httpcore-4.3.jar, you can download on the Internet yourself, or to my attachment to download, the following first put on the HttpGet request code:

String uRL = "";
HttpGet request = new HttpGet (
URL);
try {
HttpResponse response = Httpclients.createdefault (). Execute (Request);
if (Response.getstatusline (). Getstatuscode () ==200) {
result = Entityutils.tostring (response.getentity ());
}
}

The simple way to do this is because the jar package already encapsulates some basic things for us, with less effort.

In addition, recommend a free smart chat for the api-Turing device person. This is the experience page http://www.tuling123.com/openapi/cloud/proexp.jsp, it feels wonderful. Able to answer a variety of questions intelligently, such as "Hello-you." Your sister's--I have a few younger sister, you want which ", it is very interesting. This API is called through the HttpGet request, interested in the ability to try.

Post the code for the HttpPost request later.

Java the simplest way to implement HttpGet and HttpPost requests

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.