php
  • get
  • http-status-code-405
  • 2017-07-11 5 views 0 likes 
    0

    J'ai ce script et je veux faire une demande à une page, mais il me donne un 405 aide. Voici mon code:405 erreur php obtenir la demande

    $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); 
    

    Ce code retourne:

    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} 
    

    Ce code a été basé sur de ce script python: enter image description here

    +0

    Avez-vous vérifié [cette réponse] (https://stackoverflow.com/a/6609181/2464424)? – user2464424

    +0

    @ user2464424 le problème est, je n'ai aucune donnée à envoyer! – user7903682

    +1

    Oh j'ai besoin d'une demande get – user7903682

    Répondre

    0

    Si tout ce que vous avez besoin est une requête GET avec les en-têtes personnalisés et aucun corps, vous pouvez utiliser la méthode suivante qui n'a même pas besoin Curl:

    $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); 
    

     Questions connexes

    • Aucun problème connexe^_^