The examples in this article describe the HTTP request encapsulation of PHP. Share to everyone for your reference, specific as follows:
/** * Send HTTP request method, currently only support curl Send request * @param string $url request URL * @param array $params request parameter * @param string $method request method Get/po ST * @return Array $data response data */protected function http ($url, $params, $method = ' get ', $header = Array (), $multi = Fals E) {$opts = array (curlopt_timeout =>, Curlopt_returntransfer => 1, Curlopt_ssl_verifypeer => false, Curlo
Pt_ssl_verifyhost => false, Curlopt_httpheader => $header); /* Set specific parameters according to request type */switch (Strtoupper ($method)) {case ' get ': $opts [curlopt_url] = $url. ' & '.
Http_build_query ($params);
Dump ($opts [Curlopt_url]);
Break Case ' POST '://To determine whether the file is transferred $params = $multi?
$params: Http_build_query ($params);
$opts [Curlopt_url] = $url;
Dump ($opts [Curlopt_url]);
$opts [Curlopt_post] = 1;
$opts [Curlopt_postfields] = $params;
Break Default:throw New Exception (' Unsupported request way!
'); /* Initialize and Execute CURL request/* $ch = Curl_iniT ();
Curl_setopt_array ($ch, $opts);
$data = curl_exec ($ch);
$error = Curl_error ($ch);
Curl_close ($ch);
if ($error) throw new Exception (' Error in Request: '. $error);
return $data;
}
For more information about PHP interested readers can view the site topics: "Php Curl Usage Summary", "PHP Socket Usage Summary", "PHP Network Programming Skills Summary", "PHP object-oriented Programming Program Introduction", "PHP Array" operation Skills Encyclopedia, " Summary of PHP string usage, Introduction to PHP+MYSQL database operations, and a summary of PHP common database operations Tips
I hope this article will help you with the PHP program design.