duanlie1298 2013-02-18 16:40
浏览 108
已采纳

将命令行curl转换为php

i am not very curl savvy was wondering if anyone could help me turn the following into php:

curl -H "Accept: application/json" -H "Content-type: application/json" -X POST -d ' {"tester":{"email":"justin@prefinery.com","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

if you know of a good curl tutorial would also be great help.

  • 写回答

1条回答 默认 最新

  • douyouchou1085 2013-02-18 17:01
    关注

    something like this

     $ch = curl_init();
                $json = '{"tester":{"email":"justin@prefinery.com","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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?