@H_403_4@
我在Codeigniter中有如下的卷曲请求:
$order = [ 'index' => 'Value','index2' => 'Value2' ]; $this->curl->create($this->base_url.'order/'); $this->curl->http_login($creds['username'],$creds['password']); $this->curl->ssl(TRUE,2,'certificates/certificate.pem'); $this->curl->option(CURLOPT_HTTPHEADER,array('Content-Type: application/json','Accept: application/json')); $this->curl->option(CURLOPT_FAILONERROR,FALSE); $this->curl->post(json_encode($order)); $data = $this->curl->execute();
现在我需要在Laravel中发出相同的请求,我正在使用Guzzle.如何将其转换为Guzzle请求?
@H_403_4@解决方法
非常非常容易:
$client = new GuzzleHttp\Client(['base_uri' => $this->base_url]); $response = $client->request('POST','order/',[ 'form_params' => $order,'headers' => [ 'Content-Type' => 'application/json','Accept' => 'application/json' ],'auth' => [$creds['username'],$creds['password']],'http_errors' => false,'verify' => 'certificates/certificate.pem' ]); echo $response->getBody();
请注意,这与Laravel无关,它只是Guzzle. Laravel不会以任何方式影响Guzzle API.
@H_403_4@ @H_403_4@