{"id":544,"title":"hyperf\u4e2d\u7528guzzle\u53d1post raw\u8bf7\u6c42","good":0,"bad":0,"hit":2492,"created_at":"2022-12-09 04:34:18","content":"
\u4e00\u4e2a\u7a0b\u5e8f\u8981\u53d1post raw\u8bf7\u6c42\uff0c\u8bf7\u6c42\u5934\u662fjson\u7684<\/p>
\u539f\u751f\u7684\u5199\u6cd5\u662f\u8fd9\u6837\u7684\uff1a<\/p>
\/**<\/p>
* \u53d1\u9001post raw\u8bf7\u6c42<\/p>
* @param $url<\/p>
* @param $params<\/p>
* @return bool|string<\/p>
*\/<\/p>
function curlPostRaw($url, array $params)<\/p>
{<\/p>
$ch = curl_init();<\/p>
curl_setopt($ch, CURLOPT_URL, $url);<\/p>
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);<\/p>
curl_setopt($ch, CURLOPT_POST, 1);<\/p>
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));\/\/ \u5fc5\u987b\u4e3a\u5b57\u7b26\u4e32<\/p>
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application\/json'));\/\/ \u5fc5\u987b\u58f0\u660e\u8bf7\u6c42\u5934<\/p>
$res = curl_exec($ch);<\/p>
curl_close($ch);\/\/\u5173\u95ed<\/p>
return $res;<\/p>
}<\/p>
\u73b0\u8f6c\u5230hyperf\u4e2d\u9700\u8981\u8fd9\u6837\u5199\u53c2\u6570<\/p>
$url = 'https:\/\/xxx';<\/p>
$data = [<\/p>
'appId' => 'appId01',<\/p>
'globalId' => 'xxxxdsd',<\/p>
'marketType' => '',<\/p>
'pageNo' => 1,<\/p>
'pageSize' => 100,<\/p>
];<\/p>
$res = $this->httpRequestService->request('post', $url, [<\/p>
'headers' => [<\/p>
'Content-Type' => 'application\/json',<\/p>
],<\/p>
'body' => json_encode($data)<\/p>
]);<\/p>
<\/p>"}