Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP Curl to hastebin.com API不';行不通_Php_Api_Curl - Fatal编程技术网

PHP Curl to hastebin.com API不';行不通

PHP Curl to hastebin.com API不';行不通,php,api,curl,Php,Api,Curl,我想使用hastebin.com的API向其提交一个新的粘贴,这是我在以下网站上偶然发现的: 我试过几种方法,但都没能成功。以下是我的简单代码: if(function_exists('curl_init')) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://hastebin.com/documents" ); curl_setopt($ch, C

我想使用hastebin.com的API向其提交一个新的粘贴,这是我在以下网站上偶然发现的:

我试过几种方法,但都没能成功。以下是我的简单代码:

    if(function_exists('curl_init')) {
        $ch = curl_init(); 
        curl_setopt($ch, CURLOPT_URL,            "http://hastebin.com/documents" );
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 );
        curl_setopt($ch, CURLOPT_POST,           1 );
        //curl_setopt($ch, CURLOPT_POSTFIELDS,     'hello world'); 
        //curl_setopt($ch, CURLOPT_POSTFIELDS, 'data=hello world');
        curl_setopt($ch, CURLOPT_POSTFIELDS, array('data'=>'hello world'));
        curl_setopt($ch, CURLOPT_HTTPHEADER,     array('Content-Type: multipart/form-data'));
        //curl_setopt($ch, CURLOPT_HTTPHEADER,     array('Content-Type: text/plain'));

        $response_json = curl_exec($ch);
        curl_close($ch);
        $response_array = json_decode($response_json,true);
        print_r ($response_array);

    } else {
        error_log("You need cURL to use this api!");
    }

如有任何建议,将不胜感激。提前感谢。

Hastebin似乎正在将其http方案重定向到https。因此,您需要使用
https://hastebin.com/documents


其余的似乎都和以前一样。

Hastebin似乎正在将他们的http方案重定向到https。因此,您需要使用
https://hastebin.com/documents

其余的似乎都和以前一样