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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

    报告相同问题?

    悬赏问题

    • ¥15 multisim电路设计(相关搜索:设计报告)
    • ¥15 从github上下载的项目到ecplise上咋运行
    • ¥15 PC-lint Plus
    • ¥15 gpl24676注释
    • ¥15 php5.3内存泄露
    • ¥15 DigSilent如何复制复合模型到自己案例?
    • ¥15 求日版华为b610s-77a 官方公版固件,有偿
    • ¥15 关于#java#的问题,请各位专家解答!(相关搜索:java程序)
    • ¥15 linux tsi721的驱动编译后 insmod 提示 报错
    • ¥20 multisim测数据