如何使用PHP中的post方法在头部正文中发送JSON数据(cURL)

这个问题在这里已经有了答案:

  • 我可以多次使用CURLOPT_HTTPHEADER调用curl_setopt来设置多个头文件吗? 2个答案

  • 你可以使用下面的代码来实现你的目标

    $jsonData1_get_r = array(
            'customerMobileNo'=>'9040845440',
            'recipientMobileNo'=>'7008565316',
            'recipientName'=>'Name Test Test',
            'accountNo'=>'5928374737328009',
            'bankName'=>'HDFC',
            'accIfsc'=>'HDFC0002058',
            'transactionType'=>'IMPS',
            'amount'=>'100'
            ); 
    
    $jsonDataEncoded_get  = json_encode($jsonData1_get_r );
    $ch_get = curl_init($url_get);
    curl_setopt($ch_get, CURLOPT_CUSTOMREQUEST, "POST"); 
    curl_setopt($ch_get, CURLOPT_POSTFIELDS, $jsonDataEncoded_get );
    curl_setopt($ch_get, CURLOPT_RETURNTRANSFER, true);    
    curl_setopt($ch_get, CURLOPT_HTTPHEADER, array(                                                                          
        'Content-Type: application/json',                                                                                
        'Authorization: ' . $token)                                                                       
    
    );      
    

    希望你能帮助你!

    感谢和问候

    链接地址: http://www.djcxy.com/p/48893.html

    上一篇: How to send JSON data in body with header using post method in PHP(cURL)

    下一篇: Libcurl infrequently crashes on content POST