尝试使用授权(基本)连接到远程服务:
$curl = curl_init();
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_URL, 'https://online.moysklad.ru/exchange/xml/import');
curl_setopt($curl, CURLOPT_USERPWD, 'login:password');
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_POSTFIELDS, array(
'file' => '@'. ROOT .'/moysklad.xml',
'resolveByCode' => 'resolveByCode',
));
$response = curl_exec($curl);
if (curl_errno($curl)) {
echo curl_error($curl);
exit();
}
curl_close($curl);
总是得到401错误。怎么了?
答案 0 :(得分:1)
HTTP 401 - >未经授权,您使用的用户名或密码错误。