我正在尝试发布并从其他网站获取结果,但并不总是显示。
这是帖子和获取代码:
<?php
$data = array("categoryCode" => $_POST['CELL_PHONES_STORE'], "code" => $_POST['CELL_PHONE_IMEI_ESN'], "imeiEsn" => $_POST['imeiEsn'], "modelCode" => $_POST['APPLA1533IPHONE5S16GBATT'], "program" => $_POST['ATT']);
$url = 'https://atttradein.flipswap.com/api/rest/v2/serialnumbers?='.$data;
$post = curl_init();
curl_setopt($post, CURLOPT_URL, $url);
curl_setopt($post, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($post);
curl_close($post);
print_r(json_decode($result));
?>
答案 0 :(得分:1)
使用http_build_query而不是数组。更多细节http://php.net/manual/en/function.http-build-query.php。
答案 1 :(得分:1)
现在我正在尝试此代码
$data = array("categoryCode" => $_POST['CELL_PHONES_STORE'], "code" => $_POST['CELL_PHONE_IMEI_ESN'], "imeiEsn" => $_POST['imeiEsn'], "modelCode" => $_POST['APPLA1533IPHONE5S16GBATT'], "program" => $_POST['ATT'], "referer" => "https://buyback.att.com/");
//set POST variables
$url = 'https://atttradein.flipswap.com/api/rest/v2/serialnumbers?=';
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt ($ch, CURLOPT_REFERER, 'https://buyback.att.com/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_STDERR, fopen('php://output', 'w+'));
curl_setopt($ch, CURLOPT_VERBOSE, 1);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
echo $result;
&#13;