java web client 访问PHP网站时编码是传入中文的乱码的一种解法
//--java
String myname = "郑宇";
myname=URLEncoder.encode(myname, "GB2312");
String url = "http://192.168.1.101/discuznew/getParam.php";
System.out
.println(new Client()
.doPost(url, json));
//-----PHP
$valuename = $_REQUEST["v1"];
$valuename = urldecode($valuename);
echo $valuename;
//-----------------------------------------------------------------
String myname = "郑宇";
myname=URLEncoder.encode(myname, "GB2312");
String url = "http://192.168.1.101/discuznew/getParam.php";
System.out
.println(new Client()
.doPost(url, json));
//-----PHP
$valuename = $_REQUEST["v1"];
$valuename = urldecode($valuename);
echo $valuename;
//-----------------------------------------------------------------
通常,web client会以UTF-8的方式进行参数编码,当传入到默认编码是GBK的PHP时,就出现了乱码,这是我们不想看到的。