我正在尝试学习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}",
Qyouu