php curl post请求,java后台用request文件流方式接收

php curl请求:
[php]  view plain  copy
  1.       
  2.             $userid = 'test';  
  3.             $key   = 'testkey';  
  4.             $sign  = md5($userid.$key);      
  5.             $data='data';  
  6.             $data_string=json_encode(array('userid'=>$userid,'sign'=>$sign,'data'=>$data));  
  7.             $url = "http://xxx.WWW.com/quick/test";  
  8.             $ch = curl_init($url);  
  9.             curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");  
  10.             curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);//$data JSON类型字符串  
  11.             curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  
  12.             curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json''Content-Length: ' . strlen($data_string)));  
  13.             $result = curl_exec($ch);  
  14.             echo "
    ";  
  15.             print_r($result);  
  16.             echo "";  
  17.             ?>  

java 后台:
[java]  view plain  copy
  1. private static String getRequestStr(HttpServletRequest request) throws Exception {  
  2.   
  3.       StringBuilder sb = new StringBuilder();  
  4.          BufferedReader in=new BufferedReader(new InputStreamReader(request.getInputStream(),"UTF-8"));  
  5.          String line = null;  
  6.          while ((line = in.readLine()) != null) {  
  7.              sb.append(line);  
  8.          }  
  9.   
  10.      return  sb.toString();  
  11.  }  

你可能感兴趣的:(PHP)