Was ist die Curl-Request-Methode in PHP? Einführung in die vier Request-Methoden für PHP Curl

Quelle: Internet
Autor: Benutzer
Was bringt dieser Artikel für Sie über die Art und Weise angeforderte Curl in PHP? PHP Curl Anfrage Vierwege-Einführung gibt es ein bestimmten Referenzwert, besteht ein Bedarf für Freunde können beziehen sich auf ein bisschen, ich hoffe, Ihnen zu helfen.

1. senden Sie Daten im JSON Format, Adresse anfordern: HTTPS

Funktion Https_request geschützt ($url, $data = Null) {$curl = Curl_init ();    Curl_setopt ($curl, Curlopt_url, $url);    Curl_setopt ($curl, Curlopt_ssl_verifypeer, False);    Curl_setopt ($curl, Curlopt_ssl_verifyhost, False);        Wenn (! empty ($data)) {Curl_setopt ($curl, CURLOPT_POST, 1);    Curl_setopt ($curl, Curlopt_postfields, $data);    } Curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1); Die folgende Zeile ist die modifizierte Code hinzugefügt, die Host-Zugriff, Versenden von einem Datentyp der Anwendung/Json Curl_setopt einrichten konfiguriert ist ($curl, Curlopt_httpheader, Array (' Content-Typ E:Application / Json; Charset = Utf-8 "," Content-Length: '.    Strlen ($data)));    $Output = Curl_exec ($curl);    Curl_close ($curl); Return $output;}

(2) Daten im JSON Format senden, Adresse anfordern: HTTP

Funktion Curlpost ($URL, $data) geschützt {$ch = Curl_init ($URL);    Curl_setopt ($ch, Curlopt_customrequest, "POST");    Curl_setopt ($ch, Curlopt_postfields, $data); //$data JSON Typ Zeichenfolge Curl_setopt ($ch, Curlopt_returntransfer, True);    Curl_setopt ($ch, Curlopt_httpheader, Array (' Content-Typ: Anwendung / Json "," Content-Length: ' Strlen ($data));    $Result = Curl_exec ($ch);    Curl_close ($ch); Return $result;}

(3) Format für Formularübermittlung

function file_get_contents_post($url, $post){    $options = array(        'http'=> array(        'method'=>'POST',        'header' => "Content-type: application/x-www-form-urlencoded ",        'content'=> http_build_query($post),        ),    );    $result = file_get_contents($url,false, stream_context_create($options));    return $result;}$datare = file_get_contents_post("http://103.72.165.183/api/payment.aspx", $data);var_dump($datare);

Vier, $url ist die Form der Adresse sowie Daten: "ss" http://baidu.com?a= & b = "DS";

Public Function Getsslhttp ($url) {$curl = Curl_init ();        Curl_setopt ($curl, Curlopt_url, $url);        Curl_setopt ($curl, Curlopt_header, False);        Curl_setopt ($curl, Curlopt_returntransfer, True); Curl_setopt ($curl, Curlopt_ssl_verifypeer, FALSE);        HTTPS-Anforderung überprüft nicht Zertifikat und Gastgeber Curl_setopt ($curl, Curlopt_ssl_verifyhost, FALSE);        $Data = Curl_exec ($curl);        $HttpCode = Curl_getinfo ($curl, Curlinfo_http_code);        Wenn ($httpCode! =) {$data = "Https connect Timeout";        } Curl_close ($curl);    Rückkehr $data; }

Kontaktiere uns

Die Inhaltsquelle dieser Seite ist aus dem Internet, und vertritt nicht die Meinung von Alibaba Cloud; auf dieser Seite erwähnte Produkte und Dienstleistungen haben keine Beziehung zu Alibaba Cloud. Wenn der Inhalt der Seite Ihrer Meinung nach verwirrend ist, schreiben sie uns bitte eine E-Mail. Wir werden das Problem innerhalb von 5 Tagen nach Erhalt Ihrer E-Mail bearbeiten.

Wenn Sie Fälle von Plagiaten aus der Community feststellen, senden Sie bitte eine E-Mail an info-contact@alibabacloud.com und legen Sie entsprechende Beweise vor. Ein Mitarbeiter wird Sie innerhalb von 5 Werktagen kontaktieren.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.