我正在尝试学习curl。我需要将变量从 Ionic 传递到 PHP 文件。这是到目前为止的代码,我想编写传递的变量而不是硬编码值"Saurabh\"Ionic / Angular .ts 代码 create_person_name(){ console.log(this.val1); console.log('inside function'); let empname= this.val1; //let msg = "Thank you for trusting KRANTI PRODUCTS. Your Complaint Number is: " + this.ticketnumber; let params = '&empname='+this.val1; var headers = new Headers(); headers.append('Content-Type', 'application/x-www-form-urlencoded'); return this._http.post("https://example.com/" + "create-person-name.php", params, {headers: headers}) .map((response: Response) => response.json()); }PHP我该如何提及&empname来代替"Saurabh\"?<?php$curl = curl_init();curl_setopt_array($curl, array( CURLOPT_URL => "https://centralindia.api.cognitive.microsoft.com/face/v1.0/persongroups/2/persons", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => "{ \r\n \"name\" : \"Saurabh\", \r\n \"userData\" : \"TCO\" ,\r\n \"recognitionModel\": \"recognition_02\"\r\n}",
1 回答
Qyouu
TA贡献1786条经验 获得超11个赞
像这样更新帖子字段...
"{ \r\n \"name\" : \"{$_POST['empname']}\", \r\n \"userData\" : \"TCO\" ,\r\n \"recognitionModel\": \"recognition_02\"\r\n}",
您可以使用数组构建它,然后对其进行 json_encode...
$fields = array(
'name' => $_POST['empname'],
'userData' => 'TCO',
'recognitionModel' => 'recognition_02',
);
然后更新curl数组
CURLOPT_POSTFIELDS => json_encode($fields)
- 1 回答
- 0 关注
- 94 浏览
添加回答
举报
0/150
提交
取消