既然两种语言都玩,就有得对比了,先看JAVA实现,再来看PHP,当然实现的方法有很多种特别是JAVA对于同一种功能的实现绝对比PHP多很多,这点是毫无疑问的!
JAVA实现方法一:
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; } }
对于PHP的实现,简单得让人要跳楼,看代码:
<?php echo file_get_contents("http://www.jiucool.com/sendemail.php?key=j0r53nmbbd78x7m1&activatecode=2QyiF0SXXTq8");?>
PHP实在太简单了!不过有一点,PHP的弱类型语言让人实在有点不习惯,变量不声明即可使用,太不严谨了!
[...] This post was mentioned on Twitter by jiucool.com, 热点风向标. 热点风向标 said: Java 与 PHP 发送doget请求并获取远程内容 http://ff.im/-pp8YN [...]
不严谨的语言有更大的自由发挥的空间~~~严谨的语言会有更好的安全性,这个是相对的。
[Reply]
久酷
Reply:
August 20th, 2010 at 00:51
@HJin_me, 做事严谨的我 还真是有点不习惯
[Reply]