php curl curlopt_customrequest,如何将POSTMAN中的数据转换为PHP Curl Request?

我有邮递员的API.我想创建一个CURL请求并获得适当的响应.这是我的POSTMAN API.

3VkNm.png

我成功地得到了这个回应.

"{\"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: ' . strlen($data_string))

);

$result = curl_exec($ch);

curl_close($ch);

$json_result = json_decode($result, true);

echo '

';print_r($json_result);echo '
';

但我看不到我的$json_result.它只是回应< pre>< / pre>在视图中.谁能指导我?提前致谢.我想得到我的回复.

UPDATE

我使用了curl_error,它给了我以下错误.

Curl error: SSL certificate problem: self signed certificate in certificate chain

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值