1

REST API 用に PHP で cURL PUT を実行するのに問題があります。401 Unauthorized と表示され、私は PHP を初めて使用するので、どうすればよいかわかりませんでした。助けてください。

<?php
$url = "https://app.linkemperor.com/api/v2/vendors/blasts/6949235.json";
$data = '{"blasts": {"links" : "http://doblajemexicano.com.mx/sitio/index.php?title=Keyword_Elite_,_The_Ferrari_Of_Search_phrases_Study
http://fi.caravanwiki.com/index.php/Keyword_Elite_,_The_Ferrari_Of_Keywords_and_phrases_Research"}}';


            $content = json_encode($data);
            $oneMB = 1024 * 1024;
            $fh = fopen('php://temp/maxmemory:$oneMB', 'r+');
            fwrite($fh, $content);
            rewind($fh);
            $curl = curl_init($url);
            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($curl, CURLOPT_USERPWD, "<api key>:x");
            curl_setopt($curl, CURLOPT_INFILE, $fh);
            curl_setopt($curl, CURLOPT_INFILESIZE, strlen($content));
            curl_setopt($curl, CURLOPT_PUT, true);
            curl_setopt($curl, CURLOPT_TIMEOUT, 10);
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

            $json_response = curl_exec($curl);

            $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);

            if ( $status != 201 ) {
                die("Error: call to URL $url failed with status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl));
            }


            curl_close($curl);

            $response = json_decode($json_response, true);
    ?>
4

0 に答える 0