Sech
Sech

Reputation: 13

PHP curl post request with parameters

I am trying to create a new user subscription using curl, but it seems the parameters never gets sent:

$url = 'http://www.domain.com/user_sub/new';

$curl = curl_init($url);

$curl_post_data = array(
    'email' => '[email protected]',
    'f_name' => 'John',
    'l_name' => 'Doe',
    'zip_code' => 'GB211',
    'promo' => 'promocode'
);

curl_setopt($curl, CURLOPT_POST, true);

curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($curl_post_data));

curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);    

$curl_response = curl_exec($curl);

curl_close($curl);

...

If I do a straight url post over browser it works e.g:

http://www.domain.com/user_sub/[email protected]&f_name=John&l_name=Doe&zip_code=GB211&promo=promocode

What am I doing wrong please?

Upvotes: 1

Views: 3514

Answers (1)

Alhric Lacle
Alhric Lacle

Reputation: 112

have you tried doing it with:

$url = 'http://www.domain.com/user_sub/[email protected]&f_name=John&l_name=Doe&zip_code=GB211&promo=promocode';

        $response = file_get_contents($url, false);

Upvotes: 2

Related Questions