使用PHP(POST)使用cURL完成表单

时间:2016-08-15 03:36:25

标签: php ajax post curl httprequest

我正在尝试建立一个注册系统,访问我们并注册到我们网站的用户将在辅助网站上拥有一个帐户,以便他们能够看到一些机会。

所以这就是:The website were I want to POST the Form and Register

到目前为止我的代码

    <?php
    // set post fields
    $post = [
    // this i don't master fell free to approach the subject for future reffrance
    'authenticity_token'=>'vhmPffEAIiIbjo36K8CI77+YDQfMPBWEG8ymplsGJ0w=',
    'user[email]'=>'test@gmail.com',
    'user[first_name]'=>'test',
    'user[last_name]'=>'test',
    'user[password]'=>'12345678',//smart password (had to be 8char long)
    'user[country]'=>'Country(placeholder)',
    'user[mc]'=>'1560', //id of the country
    'user[lc_input]'=>'1475', //id of the dropdown
    'user[lc]'=>'1475',//id of the dropdown
    'commit'=>'REGISTER',//value of submit

    ];

    $ch = curl_init('https://auth.aiesec.org/users/sign_in');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post);

    // execute!
    $response = curl_exec($ch);

    // close the connection, release resources used
    curl_close($ch);

    // do anything you want with your response
    var_dump($response);
    ?>

故事:

作为用户,我希望能够在域A上完成表单,同时在域B上使用CURL甚至JS和AJAX创建一个帐户。

如果您有任何解决方案可以实现此目的,请告诉我:)您也可以在网站上查看。

谢谢!

延迟修改

Postman POST account

我在POSTMAN中做过这个。所以我想我应该能够发布那些信息。如果您有其他建议。

在这种情况下,服务器返回500表示成功,200表示错误(安全)

最终工作代码

    <?php

    // set post fields
    $post = [
    // this i don`t master fell free to approach the subject for future reffrance
    'authenticity_token'=>'NKWAg8mGA9gUueBaJ5Og+oEOC5O2rZarZzMK+GnjuCA=',
    'user[email]'=>'',
    'user[first_name]'=>'',
    'user[last_name]'=>'',
    'user[password]'=>'',//smart password (had to be 8char long)
    'user[country]'=>'',
    'user[mc]'=>'', //id of the country
    'user[lc_input]'=>'', //id of the dropdown
    'user[lc]'=>'',//id of the dropdown
    'commit'=>'REGISTER',//value of submit

    ];

    $ch = curl_init('https://auth.aiesec.org/users/');
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post);


    // execute!
    $response = curl_exec($ch);

    // close the connection, release resources used
    curl_close($ch);

    // do anything you want with your response
    var_dump($response);


    ?>

1 个答案:

答案 0 :(得分:2)

您是通过 https 连接的。所以你应该添加这些行:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

我测试了您的代码,网站回复了#34;错误的用户名/密码&#34;。这意味着卷曲正确连接。

相关问题