douzongluo7542 2014-12-16 21:41
浏览 43


I have been using apikitchen to reverse engineer an api for work and I'm unfamiliar with the curl library in php. I was wondering if someone could explain why the request I'm making returns a 401 error when I use curl in php, but it works fine on api kitchen.

My requests headers look like this after adding headers in api kitchen and hitting execute(I just added the deviceId and Authorization header in apikitchen):

Deviceid: someID
Authorization: Token someID
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0

The host I am pointing to is obviously fake in the example. The real host uses GET requests to grab a company name/order number, then uses the deviceID and Authorization token to authenticate the user.

Here is the code I am using for the php script:

echo 'starting...';
$curl = curl_init('');

$headers = array('deviceId'=>'someID',
                    'Authorization'=>'Token someID',

$options = array(CURLOPT_RETURNTRANSFER=>1,
                    CURLOPT_USERAGENT=>'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0',

curl_setopt_array($curl, $options);
echo curl_getinfo($curl);

$response = curl_exec($curl);

    echo curl_getinfo($curl);
    die('ERROR: "' . curl_error($curl) . '" - CODE: ' . curl_errno($curl));
    echo $response;

echo "<br>Done!";

But all i get is a 401 error:

type Status report


description This request requires HTTP authentication ().

Like I said before, using the same exact login credentials works in api kitchen, but when I assemble the requests using curl, it does not.

Any help is appreciated!

  • 写回答

1条回答 默认 最新

  • dscpg80066 2014-12-16 21:56

    It is probably the auth format that is incorrect. You need to do something like

    $headers = array('deviceId:someID',
                        'Authorization:Token someID',
    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥15 我想在一个软件里添加一个优惠弹窗,应该怎么写代码
  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流