405错误PHP获取请求 [英] 405 error php get request

查看:816
本文介绍了405错误PHP获取请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个脚本,我想向一个页面发出请求,但是它给了我一个帮助。这是我的代码:

I have this script and I want to make a request to a page, but it gives me a 405 help. Here is my code:

$result = "SOMETHING"
$kahootId = '0c17fb60-76c6-424c-9326-d1154cbc70d3';
$pageUrl = 'https://create.kahoot.it/rest/kahoots/' . $kahootId;
$quizheader = array(); 
$quizheader[] = 'content-type: application/json';
$quizheader[] = 'authorization: ' . $result;

curl_setopt($ch, CURLOPT_URL, $pageUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); 
curl_setopt($ch, CURLOPT_HEADER,$quizheader);

$store2 = curl_exec($ch);
print_r($store2);
curl_close($ch);

此代码返回:

This code returns:

HTTP/1.1 405 Method Not Allowed
Server: openresty/1.11.2.2
Date: Tue, 11 Jul 2017 20:53:03 GMT
Content-Type: application/json
Content-Length: 150
Connection: keep-alive

{"error":"javax.ws.rs.WebApplicationException","exception":"javax.ws.rs.WebApplicationException","timestamp":1499806383136,"duration":0,"errorCode":0} 

这段代码基于这个python脚本:

This code was based off of this python script:

推荐答案

$token = "SOMETHING"
$kahootId = '0c17fb60-76c6-424c-9326-d1154cbc70d3';
$url = 'https://create.kahoot.it/rest/kahoots/'.$kahootId;

$options = array(
    'http' => array(
        'method'  => 'GET',
        'header'  => "Authorization: ".$token."\r\n"
    )
);

$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);

这篇关于405错误PHP获取请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆