小编use*_*151的帖子

Ruby httparty发布请求

我有工作的PHP代码

   <?php
    $ch = curl_init("https://myurl/api/add_lead");

    $first_name = $_POST["name"];
    $phone = $_POST["phone"];
    $email = $_POST["email"];
    $ipaddress = $_SERVER['REMOTE_ADDR'];

    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch,CURLOPT_POST,true);
    curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,1120);

    curl_setopt($ch,CURLOPT_POSTFIELDS,"first_name=$first_name&phone=$phone&email=$email&ipaddress=$ipaddress");
    curl_setopt($ch,CURLOPT_HTTPHEADER,["Content-Type:application/x-www-form-urlencoded; charset=utf-8"]);

    curl_setopt($ch,CURLOPT_TIMEOUT,60);
    $result = curl_exec($ch);

    curl_close($ch);
    ?>
Run Code Online (Sandbox Code Playgroud)

我需要将其转换为红宝石代码

我试过了

HTTParty.post("https://myurl/api/add_lead",
{
:body => { first_name: "test", phone: "123456789", email: "email@email.com" , ipaddress:'192.168.0.0'},
:headers => {  'Content-Type' => 'application/x-www-form-urlencoded','charset'=>'utf-8'}

})
Run Code Online (Sandbox Code Playgroud)

但有500错误代码

怎么做呢?

php ruby post http httparty

0
推荐指数
2
解决办法
3271
查看次数

标签 统计

http ×1

httparty ×1

php ×1

post ×1

ruby ×1