Home  >  Article  >  Backend Development  >  What is the method for getting HTTP request in php

What is the method for getting HTTP request in php

王林
王林forward
2020-07-10 17:41:333274browse

What is the method for getting HTTP request in php

Get it through $_SERVER.

(Recommended tutorial: php tutorial)

Introduction:

$_SERVER is a server that contains information such as header and path , and an array of information such as script locations.

Code example:

$req_method = $_SERVER['REQUEST_METHOD'];
echo $req_method;

What is the method for getting HTTP request in php

Supplement:

socket method

Use socket to establish connection and splice HTTP Messages are sent to make HTTP requests.

An example of GET method:

\n";
} else {
 $out = "GET / HTTP/1.1\r\n";
 $out .= "Host: www.example.com\r\n";
 $out .= "Connection: Close\r\n\r\n";
 fwrite($fp, $out);
 while (!feof($fp)) {
  echo fgets($fp, 128);
 }
 fclose($fp);
}
?>

The above is the detailed content of What is the method for getting HTTP request in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:jb51.net. If there is any infringement, please contact admin@php.cn delete