来自 remove.bg api 的返回响应
Returning response from remove.bg api
我想使用 https://remove.bg api 从他们的文档中删除图像背景,因为我是 curl 的新手,这是我想出的
$url = "https://api.remove.bg/v1.0/removebg";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'x-api-key: my-api-key',
'image_url:https://example.com/image-to-remove-bg.png'
));
$server_output = curl_exec ($ch);
curl_close ($ch);
print_r($server_output);
但它返回的是空体;你能帮我解决一下吗?或者指出我哪里做错了。
image_url
应作为 POST 字段而不是 header 传递。所以这是你修改后的代码:
$url = "https://api.remove.bg/v1.0/removebg";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'x-api-key:my-api-key',
]);
// move image_url here:
curl_setopt($ch, CURLOPT_POSTFIELDS, [
'image_url' => 'https://example.com/image-to-remove-bg.png',
]);
$server_output = curl_exec($ch);
curl_close($ch);
print_r($server_output);
我想使用 https://remove.bg api 从他们的文档中删除图像背景,因为我是 curl 的新手,这是我想出的
$url = "https://api.remove.bg/v1.0/removebg";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'x-api-key: my-api-key',
'image_url:https://example.com/image-to-remove-bg.png'
));
$server_output = curl_exec ($ch);
curl_close ($ch);
print_r($server_output);
但它返回的是空体;你能帮我解决一下吗?或者指出我哪里做错了。
image_url
应作为 POST 字段而不是 header 传递。所以这是你修改后的代码:
$url = "https://api.remove.bg/v1.0/removebg";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'x-api-key:my-api-key',
]);
// move image_url here:
curl_setopt($ch, CURLOPT_POSTFIELDS, [
'image_url' => 'https://example.com/image-to-remove-bg.png',
]);
$server_output = curl_exec($ch);
curl_close($ch);
print_r($server_output);