다음 JSON 코드를 POST해야하지만 어떤 이유로 작동하지 않습니다. 아래 코드는 제가 가지고있는 코드입니다. 여기 PHP cURL, POST JSON
$fieldString = "395609399";
//the curl request processor
function processCurlJsonrequest($URL, $fieldString) { //Initiate cURL request and send back the result
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADERS, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_USERAGENT, $this->_agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_COOKIEFILE, $this->_cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $this->_cookie_file_path);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);
if ($fieldCount) { // in case of post fields present then pass it on
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode("{categoryId: $fieldString}"));
curl_setopt($ch, CURLOPT_POST, 1);
}
$resulta = curl_exec($ch);
if (curl_errno($ch)) {
print curl_error($ch);
} else {
curl_close($ch);
}
return $resulta;
}
는 컬 요청을 호출하는 기능이다
function get_cat($categoryId, $URL) {
$fields = array(
"categoryId" => $categoryId
);
$fields_string = $fields;
return $this->processCurlJsonrequest($URL, $fields_string);
}
json_encode에 이미 JS 객체 형식의 문자열이 아닌 PHP 배열을 지정합니다. – JAL
curl_setopt ($ ch, CURLOPT_POSTFIELDS, array (json_encode (array ( "categoryId"=> "5016"))));)를 시도했습니다. 및 json_encode (배열 ( "categoryId"=> "5016")))); 그리고 작동하지 않습니다 – Michael
당신이 분명히 문제를 풀었지만 해결 방법이 무엇인지 나타 내기 위해 게시물을 업데이트하지 않은 것은 매우 귀찮습니다. 일부 이유 때문에 – shanusmagnus