今天遇到一点小坑需要与java对接,以数据流的形式发送
^_^
发送数据只要是字符串格式就可以…….
/**
* curl post java对接 传输数据流
* */
public function curlPost($Url, $data){
$ch = curl_init($Url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);//$data JSON类型字符串
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($data)));
$result = curl_exec($ch);
curl_close ( $ch );
return $result;
}