脚本宝典收集整理的这篇文章主要介绍了如何将POSTMAN中的数据转换为PHP Curl Request?,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我成功地得到了这个回应.
"{\"Request\":{\"state\":\"Manama\",\"address\":\"406 Falcon Tower\",\"address2\":\"Diplomatic Area\",\"cITy\":\"Manama\",\"country\":\"BH\",\"fullname\":\"Dawar Khan\",\"postal\":\"317\"},\"Response\":{\"status\":\"Success\",\"code\":100,\"message\":\"Address is verified\"}}"
现在我想在我的PHP代码中使用这个API调用.我用过这段代码.
$data = array( 'Request' => 'ValidateAddress','address' => test_input($form_data->address),'secondAddress' => test_input($form_data->secondAddress),'city' => test_input($form_data->city),'country' => test_input($form_data->country),'name' => test_input($form_data->name),'zipCode' => test_input($form_data->zipCode),'merchant_id' => 'shipm8','hash' => '09335f393d4155d9334ed61385712999' ); $data_string = json_encode($data); $url = 'myurl.COM/'; $ch = curl_init($url); curl_setopt($ch,CURLOPT_CUSTOMREQUEST,"POST"); curl_setopt($ch,CURLOPT_POSTFIELDS,$data_string); curl_setopt($ch,CURLOPT_RETURNtransfer,true); curl_setopt($ch,CURLOPT_HTTPHEADER,array( 'Content-tyPE: application/json','Content-Length: ' . @R_512_1141@($data_string)) ); $result = curl_exec($ch); curl_close($ch); $json_result = json_decode($result,true); echo '<PRe>';print_r($json_result);echo '</pre>';
但我看不到我的$json_result.它只是回应< pre>< / pre>在视图中.谁能指导我?提前致谢.我想得到我的回复.
UPDATE
我使用了curl_error,它给了我以下错误.
冗长,耗时但干净
>在Web浏览器中访问URL.
>打开安全细节.
>出口证明.
>相应地更改cURL选项.
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,true); curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,2); curl_setopt($ch,CURLOPT_CaiNFO,getcwd() . "/CACERts/BuiltinObjectToken-EquifaxSecureCA.crt");
快但脏
curl_setopt($ch,false);
我们正在配置cURL以接受任何服务器(对等)证书.从安全角度来看,这不是最佳选择.
摘录自very detailed and precise article的截图,以便更好地理解.请在生产现场实际实施之前参考相同的内容.
以上是脚本宝典为你收集整理的如何将POSTMAN中的数据转换为PHP Curl Request?全部内容,希望文章能够帮你解决如何将POSTMAN中的数据转换为PHP Curl Request?所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。