在java中實現(xiàn)php的md5加密的方法:首先搭建好php的環(huán)境;然后寫一個通過提取get參數(shù),并對值進行md5加密的頁面;最后在java頁面進行提交。
在java中實現(xiàn)php的md5加密的方法:
1、搭建好php的環(huán)境(不作介紹),寫一個通過提取get參數(shù),并對值進行md5加密的頁面,如下
<?php echo strtoupper(md5($_get["md5str"])); ?> strtoupper是字母大寫轉(zhuǎn)換的函數(shù)
md5是md5加密的函數(shù)
$_get["md5str"]就是通過url帶一個md5str的參數(shù),把值獲取并打印出來
相關(guān)學(xué)習(xí)推薦:php編程(視頻)
2、java頁面的提交方法
/* 用于做php的提交處理* @param url*/public static string phprequest(string url){try{httpclient client = new httpclient();postmethod post = new postmethod(url);//使用post方式提交數(shù)據(jù)post.setrequestheader("content-type","text/html; charset=utf-8"); client.executemethod(post); string response = new string(post.getresponsebodyasstring().getbytes("8859_1"), "utf-8");//打印結(jié)果頁面 post.releaseconnection(); return response;} catch(ioexception e){e.printstacktrace();return null;}} 需要提示的是,url記得先對中文參數(shù)進行一次utf-8的編碼再傳到這個方法里面,這個方法對響應(yīng)的結(jié)果做了反編碼的處理,最后就能正確的返回php md5加密后的值了!
相關(guān)學(xué)習(xí)推薦:java基礎(chǔ)教程