PHP + curl, HTTP POST sample code?

前端 未结 11 2344
北荒
北荒 2020-11-21 04:58

Can anyone show me how to do a php curl with an HTTP POST?

I want to send data like this:

username=user1, password=passuser1, gender=1
11条回答
  •  执念已碎
    2020-11-21 05:44

    Examples of sending form and raw data:

    $curlHandler = curl_init();
    
    curl_setopt_array($curlHandler, [
        CURLOPT_URL => 'https://postman-echo.com/post',
        CURLOPT_RETURNTRANSFER => true,
    
        /**
         * Specify POST method
         */
        CURLOPT_POST => true,
    
        /**
         * Specify array of form fields
         */
        CURLOPT_POSTFIELDS => [
            'foo' => 'bar',
            'baz' => 'biz',
        ],
    ]);
    
    $response = curl_exec($curlHandler);
    
    curl_close($curlHandler);
    
    echo($response);
    

提交回复
热议问题