0

我正在尝试使用 curl 像这样创建粘贴:

$ url="http://pastebin.com/api/api_post.php"
$ headers="Content-Type: text/html; charset=UTF-8"
$ data="api_option=paste&api_dev_key=<my-key-here>&api_paste_code=testing&api_option=paste"
$ curl -X POST -H "$headers" --data "$data" $url

但是我没有取回我的粘贴网址,而是在这篇文章的标题中得到了错误

老实说,我很惊讶,似乎没有任何合理的解决方案可以从 OSX 命令行进行粘贴。

*更新我*

通过比较,这个小的 PHP 脚本运行良好:

<?
$ch = curl_init('http://pastebin.com/api/api_post.php');
$api_dev_key = '<my-key-here>';
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'api_option=paste&api_dev_key='.$api_dev_key.'&api_paste_code=testing');
curl_setopt($ch, CURLOPT_VERBOSE, 1);

echo curl_exec($ch) . "\n";
?>

那么有什么不同呢?

4

1 回答 1

2

我认为你的标题不正确。它应该是:

$ headers="Content-Type: application/x-www-form-urlencoded; charset=UTF-8"
于 2015-06-27T04:43:54.230 回答