Rumah > Soal Jawab > teks badan
Seperti tajuknya,
$data = $textArray['content'];// 是个字符串
$params = array('top_k'=>10);
$ch = curl_init();
curl_setopt_array($ch,
CURLOPT_POSTFIELDS => json_encode($data,$params,JSON_UNESCAPED_UNICODE),
));// 这里其他部分省略了
Ini yang saya tulis
Tetapi apabila mencetak json_encode($data,$params,JSON_UNESCAPED_UNICODE), ia didapati kosong
Kemudian tulis CURLOPT_POSTFIELDS => json_encode($data,JSON_UNESCAPED_UNICODE),json_encode($params,JSON_UNESCAPED_UNICODE),
Dengan cara ini anda mendapati $params tidak diluluskan
Sila jawab, terima kasih
高洛峰2017-05-31 10:35:46
Kaedah 1
$data = $textArray['content'];// 是个字符串
$params = array('top_k'=>10);
$array = [];
$array['data'] = $data;
$array['params'] = $params;
$ch = curl_init();
curl_setopt_array($ch,
CURLOPT_POSTFIELDS => json_encode($array,JSON_UNESCAPED_UNICODE),
));
//code.....
Kaedah 2
$data = $textArray['content'];// 是个字符串
$params = array('top_k'=>10);
$params['data'] = $data;
$ch = curl_init();
curl_setopt_array($ch,
CURLOPT_POSTFIELDS => json_encode($params,JSON_UNESCAPED_UNICODE),
));
//code.....
Variasi kaedah 2
$data = $textArray['content'];// 是个字符串
$params = array('top_k'=>10,'data'=>$data);
$ch = curl_init();
curl_setopt_array($ch,
CURLOPT_POSTFIELDS => json_encode($params,JSON_UNESCAPED_UNICODE),
));
//code.....
Kaedah 3 Versi ringkas
$ch = curl_init();
curl_setopt_array($ch,
CURLOPT_POSTFIELDS => json_encode(array('top_k'=>10,'data'=>$textArray['content']),JSON_UNESCAPED_UNICODE),
));
//code.....
Itu sahaja. . . .
Saya dapati anda tidak tahu asas php. .
某草草2017-05-31 10:35:46
curl_setopt_array($ch,
CURLOPT_POSTFIELDS => json_encode($data,$params,JSON_UNESCAPED_UNICODE),
));
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json'
);
//接收
$data = file_get_contents('php://input');