0
/**
 * 创建购物车
 * @param $source
 * @param $token
 * @param string $view
 * @return mixed
 * @throws Exception
 * @internal param $data
 */
public function createCart($source, $token, $view = 'default')
{
    $supplier = $this->_help->getSupplier($source);
    $api = $supplier['host'] . "index.php/rest/{$view}/V1/carts/mine";
    $this->_curl->setCredentials($supplier['username'],$supplier['password']);
    $this->_curl->addHeader('Content-Type','application/json');
    $this->_curl->addHeader('Authorization','Bearer '.$token);
//        $this->_curl->setHeaders(array(
//            'Content-Type'=>'application/json',
//            'Authorization'=>'Bearer '.$token
//        ));
        $this->_curl->post($api, json_encode(array(),true));
        var_dump($this->_curl->getHeaders());die;
        return $this->_curl->getBody();
    }

Response : enter image description here

0

Please try with below code :

$headers = ["Content-Type" => "application/json", "Content-Length" => "200"];
$this->curl->setHeaders($headers);

hope its working for you

| improve this answer | |
  • I have solve it myself ! It wasn't work because I used it for the first time.Think you! You may have noticed my comments,I used your advice. The problem is caused by the token error. – 秋枫雁飞 Aug 16 '19 at 2:58
0

I have solve it myself ! It wasn't work because I used it for the first time.Think you! You may have noticed my comments,I used your advice. The problem is caused by the token error.the token may be is like this ""token"" so have this error.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.