【发布时间】:2020-12-17 07:33:23
【问题描述】:
这是我在这里的第一篇文章。我希望我的问题是正确的。 我使用谷歌翻译从德语到英语,因为我的英语不是那么好。
我想使用easybill 的“api”。得到工作。但不幸的是,我无法使用 POST。
我希望有人可以帮助我。
我想创建一个新客户进行测试。我的目标是稍后使用 PHP 生成发票。 easybill 的“api”可以在这里找到:https://www.easybill.de/api/
我尝试了以下代码,但不幸的是我找不到错误。
$url = "https://api.easybill.de/rest/v1/customers";
$data = array(
'first_name' => 'Foo',
'last_name' => 'Bar',
'company_name' => 'FooBar GmbH',
'emails' => array ('foo.bar@foobar.com'
)
);
$postdata = json_encode(array($data));
$accesstoken = "XXXXXXXXXXX";
$headr = array();
$headr[] = 'Content-length: 0';
$headr[] = 'Content-type: application/json';
$headr[] = 'Authorization: Bearer '.$accesstoken;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headr);
$result = curl_exec($ch);
curl_close($ch);
print_r ($result);
来自德国的问候。
【问题讨论】:
-
您尝试 POST 时的确切错误是什么?
-
400 错误请求 nginx
-
Content-length: 0 肯定不对。
-
谢谢。现在我更进一步了。 :-) 我注释掉了这一行。现在出现错误消息: {"code":20000,"message":"Bitte f\u00fcllen Sie alle Felder aus.","arguments":["last_name","company_name"]} 但数据已填写。