POST-Befehl mit DIGEST-Authentifizierung.

Einklappen
X
 
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge
  • Tico
    Lox Guru
    • 31.08.2016
    • 1035

    #16
    Gibt jetzt einen Fehler unten mit Christians Code...
    Ich spreche kein Deutsch. Gib Google Translate die Schuld, wenn ich unverständlich bin.

    Kommentar

    • Christian Fenzl
      Lebende Foren Legende
      • 31.08.2015
      • 11238

      #17
      Probier mal den Wert ohne Anführungszeichen:

      $post_data = array(
      'suspension_time_seconds' => 10800
      );
      Hilfe für die Menschen der Ukraine: https://www.loxforum.com/forum/proje...Cr-die-ukraine

      Kommentar

      • Tico
        Lox Guru
        • 31.08.2016
        • 1035

        #18
        Works! Thankyou, thankyou, thankyou!

        This the full code -

        PHP-Code:
        <?php
        ###################################################
        # TODO: Update IP address, username and password
        $ip = "x.x.x.x";
        
        $username = "username";
        $password = "password";
        ###################################################
        
        # TEST URL: $url = "https://httpbin.org/digest-auth/auth/user/passwd";
        $url = "http://" . $ip . "/servicecgi-bin/suspend_battery_calibration/";
        
        $post_data = array(
            'suspension_time_seconds' => 10800
        );
        $data_string = json_encode($post_data);
        $options = array(
            CURLOPT_URL            => $url,  
            CURLOPT_VERBOSE        => false,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_FOLLOWLOCATION => true,
            CURLOPT_SSL_VERIFYPEER => false,
            CURLOPT_USERPWD        => $username . ":" . $password,
            CURLOPT_HTTPAUTH       => CURLAUTH_DIGEST,
            CURLOPT_HTTPHEADER => array('Content-Type:application/json'),
            CURLOPT_POST           => true,
            CURLOPT_CUSTOMREQUEST  => 'POST',
            CURLOPT_POSTFIELDS     => $data_string,
        );
        
        $ch = curl_init();
        
        curl_setopt_array( $ch, $options );
        
        try {
          $raw_response  = curl_exec( $ch );
        
          echo $raw_response;
        
          // validate CURL status
          if(curl_errno($ch))
              throw new Exception(curl_error($ch), 500);
        
          // validate HTTP status code (user/password credential issues)
          $status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
          if ($status_code != 200)
              throw new Exception("Response with Status Code [" . $status_code . "].", 500);
        
        } catch(Exception $ex) {
            if ($ch != null) curl_close($ch);
        
            throw new Exception($ex);
        }
        
        if ($ch != null) curl_close($ch);
        
        ?>
        Ich spreche kein Deutsch. Gib Google Translate die Schuld, wenn ich unverständlich bin.

        Kommentar

        Lädt...