本文主要是介绍php curl Content-Type: application/x-www-form-urlencoded,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
public function test(){$url = 'xxx'; //请求域名$method = 'POST';$params = ['inputCharset'=>'UTF-8','signType'=>'RSA','sign'=>'xxx',//签名'payIp'=>'127.0.0.1','returnUrl'=>'xxx', //地址'notifyUrl'=>'xxx', //回调地址'deviceType'=>'WEB','payType'=>'CARDBANK','merchantId'=>4613,'merchantTradeId'=>'4245368915748504','currency'=>'JPY','amountFee'=>'1','goodsTitle'=>'remare_by_xh','issuingBank'=>'UNIONPAY',// 'subIssuingBank'=>'123456','version'=>'1.0',];$p='';foreach ($params as $k => $v) {$p .= $k.'='.$v.'&';}$data = rtrim($p, '&');$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);curl_setopt($ch, CURLOPT_HEADER, true);// 设置User-Agent// curl_setopt($ch, CURLOPT_USERAGENT, self::USER_AGENT);// 连接建立最长耗时curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);// 请求最长耗时curl_setopt($ch, CURLOPT_TIMEOUT, 30);// 设置SSL版本curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);// 如果报证书相关失败,可以考虑取消注释掉该行,强制指定证书版本//curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, 'TLSv1');// 设置Basic认证curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);// curl_setopt($ch, CURLOPT_USERPWD, $this->appKey . ":" . $this->masterSecret);// 设置Post参数if ($method === 'POST') {curl_setopt($ch, CURLOPT_POST, true);} else if ($method === 'DELETE' || $method === 'HTTP_PUT') {curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);}curl_setopt($ch, CURLOPT_POSTFIELDS, $data);// 设置headerscurl_setopt($ch, CURLOPT_HTTPHEADER, array(// 'Content-Type: application/json','Content-Type: application/x-www-form-urlencoded','Connection: Keep-Alive',));// 执行请求$output = curl_exec($ch);// 解析Response$response = array();$errorCode = curl_errno($ch);if ($errorCode) {var_dump(123);var_dump($errorCode);} else {$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);$header_text = substr($output, 0, $header_size);$body = substr($output, $header_size);$headers = array();foreach (explode("\r\n", $header_text) as $i => $line) {if (!empty($line)) {if ($i === 0) {$headers['http_code'] = $line;} else if (strpos($line, ": ")) {list ($key, $value) = explode(': ', $line);$headers[$key] = $value;}}}$response['headers'] = $headers;$response['body'] = $body;$response['http_code'] = $httpCode;}curl_close($ch);var_dump($body);die;return $response;}
这篇关于php curl Content-Type: application/x-www-form-urlencoded的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!