php curl请求:
<?php
$userid = 'test';
$key = 'testkey';
$sign = md5($userid.$key);
$data='data';
$data_string=json_encode(array('userid'=>$userid,'sign'=>$sign,'data'=>$data));
$url = "http://xxx.WWW.com/quick/test";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);//$data JSON类型字符串
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($data_string)));
$result = curl_exec($ch);
echo "<pre>";
print_r($result);
echo "</pre>";
?>
java 后台:
private static String getRequestStr(HttpServletRequest request) throws Exception {
StringBuilder sb = new StringBuilder();
BufferedReader in=new BufferedReader(new InputStreamReader(request.getInputStream(),"UTF-8"));
String line = null;
while ((line = in.readLine()) != null) {
sb.append(line);
}
return sb.toString();
}