Home  >  Article  >  Backend Development  >  How to set php post without parameters

How to set php post without parameters

藏色散人
藏色散人Original
2021-06-03 09:19:292017browse

php post parameter-free setting method: 1. Request the interface through ajax; 2. The client requests through curl; 3. Execute "file_get_contents("php://input");" on the PHP server.

How to set php post without parameters

The operating environment of this article: Windows 7 system, PHP 7.1 version, DELL G3 computer

No parameter name post data client and how to interface it Realized?

PHP version client:

1. The first case is that the client requests the interface through ajax.

 $.ajax({
     type: 'POST',
     url: url ,
     data: data ,
     success: success ,
     dataType: dataType
});

2. The second case is that the client can request through curl.

$ch = curl_init();     
//设置URL,POST方式提交以及POST数据   
curl_setopt($ch, CURLOPT_URL, $apiurl);   
curl_setopt($ch, CURLOPT_POST,1);   
curl_setopt($ch, CURLOPT_POSTFIELDS, "post数据");        
$result = curl_exec($ch);

PHP version server:

 $sendjson=file_get_contents("php://input");
 print_r($sendjson);

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to set php post without parameters. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn