作者 karlet

feat:增加body提交方式

... ... @@ -25,7 +25,7 @@ class Curl
}
//post 获取数据
static public function httpPost($url, $param = [], $header = [])
static public function httpPost($url, $param = [], $header = [], $asBody = false)
{
if (empty($url)) {
return false;
... ... @@ -45,7 +45,24 @@ class Curl
}
}
$opts[CURLOPT_POSTFIELDS] = $isJson ? json_encode($param) : http_build_query($param);
if ($asBody) {
// form-data格式提交
$boundary = '----WebKitFormBoundary' . uniqid();
$body = '';
foreach ($param as $key => $value) {
var_dump($key, $value);
$body .= "--$boundary\r\n";
$body .= "Content-Disposition: form-data; name=\"$key\"\r\n\r\n";
$body .= "$value\r\n";
}
var_dump($body);
$body .= "--$boundary--\r\n";
$opts[CURLOPT_POSTFIELDS] = $body;
$header[] = "Content-Type: multipart/form-data; boundary=$boundary";
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
} else {
$opts[CURLOPT_POSTFIELDS] = $isJson ? json_encode($param) : http_build_query($param);
}
curl_setopt_array($ch, $opts);
$output = curl_exec($ch);
... ... @@ -55,6 +72,7 @@ class Curl
curl_close($ch);
return $output;
}
//delete 请求
static public function httpDelete($url, $param = [], $header = [])
{
... ...