既然兩種語言都玩,就有得對比了,先看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的弱類型語言讓人實在有點不習慣,變量不聲明即可使用,太不嚴謹了!aspx">