Java and PHP send get requests and obtain remote content

Source: Internet
Author: User

Since both languages are used, we have to compare them. Let's first look at JAVA Implementation and then PHP, of course, there are many implementation methods, especially JAVA, for the implementation of the same function is definitely much more than PHP, this is undoubtedly!

JAVA Implementation Method 1:

Package com. jiucool. www. struts. action;

Import java. io. BufferedReader;
Import java. io. IOException;
Import java. io. InputStreamReader;
Import java.net. MalformedURLException;
Import java.net. URL;
Import java.net. URLConnection;

Public class doget_http_request {

Public String doget_http_request (){
StringBuffer readOneLineBuff = new StringBuffer ();
String content = "";
Try {
URL url = new URL ("http://www.jiucool.com/sendemail.php? Key = j0r53nmbbd78x7m1 "+" & activatecode = 2QyiF0SXXTq8 ");
URLConnection conn = url. openConnection ();
BufferedReader reader = new BufferedReader (new InputStreamReader (conn. getInputStream ()));
String line = "";
While (line = reader. readLine ())! = Null ){
ReadOneLineBuff. append (line );
}
Content = readOneLineBuff. toString ();
Reader. close ();
} Catch (MalformedURLException e ){
E. printStackTrace ();
} Catch (IOException e2 ){
E2.printStackTrace ();
}
Return content;
}
}

For PHP implementation, it is easy to skip the building and check the Code:

<? PhpEcho File_get_contents("Http://www.jiucool.com/sendemail.php? Key = j0r53nmbbd78x7m1 & activatecode = 2QyiF0SXXTq8");?>

PHP is too simple! However, the weak PHP language is a bit unaccustomed. variables can be used without being declared. It is too rigorous!Aspx ">

Related Article

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.