![](/img/trans.png)
[英]I'm trying to make a function (button) to upload images to my database in CodeIgniter (PHP). But I'm getting an error
[英]I'm getting an error when trying to POST a new user to my my cUrl testing enviroment in php
我是新手,正在尝试在 php 中学习 cURL,但是当尝试将我的新用户发布到我的测试环境时出现错误。
我已经尝试调试并寻找各种东西,但找不到任何具体错误的东西。 我也尝试过谷歌搜索,但我发现的所有答案都没有意义输入
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);
}
我只想将用户添加到环境中,但没有任何反应。 只有当我 var_dump'd 找到问题时,我才收到错误消息。
您需要json_encode()
$post 数据。
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post)); //Post Fields
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.