简体   繁体   English

尝试在 php 中将新用户发布到我的 cUrl 测试环境时出现错误

[英]I'm getting an error when trying to POST a new user to my my cUrl testing enviroment in php

im new and trying to learn cURL in php but when trying to POST my new made user to my testing enviroment i get an error.我是新手,正在尝试在 php 中学习 cURL,但是当尝试将我的新用户发布到我的测试环境时出现错误。

I've tried debugging and looking for various things but couldn't find anything in specific that was wrong.我已经尝试调试并寻找各种东西,但找不到任何具体错误的东西。 I tried googling as well but all the answers i found made no sense enter我也尝试过谷歌搜索,但我发现的所有答案都没有意义输入

string(830) "{"status":400,"error":"There was a problem in the JSON you submitted [92677fc5f9526c8878a88c61e3ca5a27]: unexpected characters after the JSON document () at line 1, column 1 [parse.c:618] 
in '--------------------------7c5256387e2a9ed5\r\nContent-Disposition: 
attachment; name=\"name\"\r\n\r\njohn jeff\r\n-------------------------

-7c5256387e2a9ed5\r\nContent-Disposition: attachment; 
name=\"email\"\r\n\r\nhelloyes@hotmail.com\r\n-------------------------

-7c5256387e2a9ed5\r\nContent-Disposition: attachment; name=\"phone\"\r\n\r\n09009090\r\n-------------------------

-7c5256387e2a9ed5\r\nContent-Disposition: attachment; name=\"companies\"\r\n\r\nLandstede\r\n-------------------------

-7c5256387e2a9ed5\r\nContent-Disposition: attachment; name=\"user_id\"\r\n\r\n420\r\n--------------------------
7c5256387e2a9ed5--\r\n"}"
if (isset($_POST['submit'])) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://api.intercom.io/users");
    curl_setopt($ch, CURLOPT_POST, 1);
    if (isset($_POST['unsubscribed_from_emails'])) {
        $post = ['name' => $_POST['name'],
            'email' => $_POST['email'],
            'phone' => $_POST['phone'],
            'companies' => $_POST['companies'],
            'user_id' => $_POST['user_id'],
            'unsubscribed_from_emails' => $_POST['unsubscribed_from_emails']
        ];
    } else {
        $post = ['name' => $_POST['name'],
            'email' => $_POST['email'],
            'phone' => $_POST['phone'],
            'companies' => $_POST['companies'],
            'user_id' => $_POST['user_id']
        ];
    }
  //var_dump($post);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post);  //Post Fields
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    $headers = [
        'Authorization:Bearer <MYKEYYOUCANTSEE>',
        'Accept: application/json',
        'Content-type: application/json',
    ];

    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

    $server_output = curl_exec($ch);

    curl_close($ch);

  //  var_dump($server_output);
}

I just want the user to be added to the enviroment but nothing happens.我只想将用户添加到环境中,但没有任何反应。 Only when i var_dump'd to find the problem i got that errormessage.只有当我 var_dump'd 找到问题时,我才收到错误消息。

You need to json_encode() the $post data.您需要json_encode() $post 数据。

curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post));  //Post Fields

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我正在尝试使一个函数(按钮)将图像上传到CodeIgniter(PHP)中的数据库。 但是我出错了 - I'm trying to make a function (button) to upload images to my database in CodeIgniter (PHP). But I'm getting an error php postgresql-我尝试插入字符串时请求中的错误 - php postgresql - error in my request when i'm trying to insert a string 我正在尝试将 curl 与 php 一起使用,但出现此错误:无法解析主机:承载 - I'm trying to use curl with php but getting this error:Could not resolve host: Bearer 我的 PHP 表单的显示页面出现错误 - I'm getting an error in the Display page of my PHP form 当我打开我的 WordPress 网站时出现错误 - I'm getting an error when I open my WordPress site 我正在尝试使用mysqli查询我的mysql数据库,但是却出现内存错误 - I'm trying to query my mysql db with mysqli, however I'm getting memory error 尝试在本地计算机上设置 wordpress 时遇到此错误,但因错误而失败 - I'm facing this error when trying to setup my wordpress on my local machine, but failed with error 我正在尝试将表单链接到我的PHP页面,当他单击“提交”按钮时,我想将用户的输入输出到该页面上 - I'm trying to link my form to my PHP page, and I want to print out the user's input onto that page when he clicks the submit button 我是PHP新手,但出现此错误: - I'm new in PHP and I'm getting this error: 不理解我在数组中遇到的错误 - Not understanding the error I'm getting in my array
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM