我如何将此命令翻译成php?
curl -k -3 -X POST https://dsp-yourdsp.cloud.dreamfactory.com/rest/user/session \
-H "X-DreamFactory-Application-Name: NotImportant" \
-d '{ "email" : "foo@bar.com", "password" : "yourpassword" }'
到目前为止:
$url = 'https://dsp-yourdsp.cloud.dreamfactory.com/rest/user/session';
$curl = curl_init();
curl_setopt($curl, CURLOPT_HTTPHEADER, array('X-DreamFactory-Application-Name: NotImportant'));
// Covers -H
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, 1); // Covers -X
curl_setopt($curl, CURLOPT_POSTFIELDS, '{ "email" : "foo@bar.com", "password" : "yourpassword" }');
// Covers -d
curl_exec($curl);
我想我错过了:-k,-3对吗?或者我有什么不对劲?以上看起来是否合适?
似乎无法在https://php.net/manual/en/function.curl-setopt.php中找到-k,-3。
感谢。
答案 0 :(得分:0)
尝试在设置CURLOPT_POSTFIELDS之前将数据创建为数组,然后json_encode()将其创建。
$ data = json_encode(数组("电子邮件" =>" foo@bar.com","密码" =>" yourpassword& #34));
curl_setopt($ curl,CURLOPT_POSTFIELDS,$ data);