2 / * . 3 the POST /servlet/ICBCCMPAPIReqServlet?userID=2345YQ.y.1001&PackageID=201807311347539185&SendTime=20180731134755 the HTTP / 1.1 . 4 the Host: 127.0.0.1:7070 . 5 the Accept: * . 6 the Content-the Type: file application / X-WWW-form-urlencoded . 7 the Content-the Length: 4211 . 8 the Expect: 100-Continue . 9 10 * / . 11 12 is / * 13 is the HTTP / 1.1 the Continue 100 14 * / 15 16 / * * . 17 * * curlPost request 18 is * @param String $ URL request URL . 19 * @param array data sent $ dataArr 20 * @Param string $ dataType data type transmission 21 is * @param Array $ headerArr request header 22 is * @param timeout int timeout $ 23 is * @author: songjm 24 * @date: 2018.7.31 25 * @return Array 26 is * / 27 function curlPost ( $ URL , $ dataArr , $ dataType = 'ARR', $ headerArr = Array (), $ timeout =. 3 ) 28 { 29 $ headerArr [] = 'the Expect:' 30 // prevent transmission of greater than 1024 bytes libcurl enable HTTP / 1.1 when data Expect: 100-continue characteristic 31 $ CHCurl_init = (); // initialize the curl 32 curl_setopt ( $ CH , CURLOPT_RETURNTRANSFER, to true ); // return string without directly output 33 is curl_setopt ( $ CH , CURLOPT_URL to, $ URL ); // set request URL 34 is curl_setopt ( $ CH , CURLOPT_HTTPHEADER, $ headerArr ); 35 curl_setopt ( $ CH , CURLOPT_TIMEOUT, $ timeout ); 36 curl_setopt ( $ CH , CURLOPT_SSL_VERIFYPEER, to false ); // not verify other certificates 37 curl_setopt ( $ CH , CURLOPT_SSL_VERIFYHOST, 0); // not check server SSL certificate 38 is 39 $ dataType = strtolower ( $ dataType ); 40 IF ( $ dataType == 'JSON' ) 41 is { 42 is $ Data = json_encode ( $ dataArr ) ; 43 is } 44 is ELSEIF ( $ dataType == 'Ser' ) 45 { 46 is $ Data = the serialize ( $ dataArr ); 47 } 48 ELSEIF ( $ dataType == 'RAW' ) 49 { 50 $ Data = $ dataArr ; 51 is } 52 is the else 53 is { 54 is $ Data = http_build_query ( $ dataArr ); 55 } 56 is curl_setopt ( $ CH , CURLOPT_POST, to true ); // POST request set 57 is curl_setopt ( $ CH , CURLOPT_POSTFIELDS, $ data ); // setting request is POST (string or array) 58 59 $response = curl_exec($ch); 60 if ($error = curl_error($ch)) 61 { 62 $bkArr = array( 63 'code' => 0, 64 'msg' => $error, 65 ); 66 } 67 else 68 { 69 $bkArr = array( 70 'code' => 1, 71 'msg' => 'ok', 72 'resp' => Response $ , 73 is ); 74 } 75 76 curl_close ( $ CH ); // close cURL resource release 77 78 return $ bkArr ; 79 }