PHP + curl, HTTP POST sample code?

前端 未结 11 2346
北荒
北荒 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:40

    It's can be easily reached with:

     'user1',
        'password' => 'passuser1',
        'gender'   => 1,
    ];
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'http://www.domain.com');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
    $response = curl_exec($ch);
    var_export($response);
    

提交回复
热议问题