2013-02-18 111 views
1

我不是很卷曲精明想知道是否有人能帮助我把下面的到PHP:翻译命令行卷曲到PHP

curl -H "Accept: application/json" -H "Content-type: application/json" -X POST -d ' {"tester":{"email":"[email protected]","status":"applied","profile":{"first_name": "Justin", "last_name": "Britten"},"responses":{"response":[{"question_id":"23874", "answer":"a text response"},{"question_id":"23871", "answer":"1"},{"question_id":"23872", "answer":"0,2"},{"question_id":"23873", "answer":"9"}]}}}' https://account.prefinery.com/api/v2/betas/1/testers.json?api_key=secret

,如果你知道一个良好的卷曲教程也将是巨大的帮帮我。

+3

那么他们几乎具有相同的类似物。查看curl的'manpage',而不是使用什么选项,然后与['curl_setopt'](http://php.net/manual/en/function.curl-setopt.php)文档进行比较以查看php equiv。 – prodigitalson 2013-02-18 16:44:35

+0

你会介意提供一个链接到这些网页?对不起我的无知。 – 2013-02-18 16:53:46

+0

有评论中的链接... – 2013-02-18 16:54:13

回答

0

像这样

$ch = curl_init(); 
      $json = '{"tester":{"email":"[email protected]","status":"applied","profile":{"first_name": "Justin", "last_name": "Britten"},"responses":{"response":[{"question_id":"23874", "answer":"a text response"},{"question_id":"23871", "answer":"1"},{"question_id":"23872", "answer":"0,2"},{"question_id":"23873", "answer":"9"}]}}}'; 
      $url = 'https://account.prefinery.com/api/v2/betas/1/testers.json?api_key=secret'; 
      curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json', 'Accept: application/json')); 
      curl_setopt($ch, CURLOPT_HEADER, 0); 
      curl_setopt($ch, CURLOPT_POST, 1); 
      curl_setopt($ch, CURLOPT_POSTFIELDS, $json); 
      curl_setopt($ch, CURLOPT_URL, $url); 
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
      $result = curl_exec($ch); 
+0

谢谢阿梅兹我会尝试 – 2013-02-18 17:43:40