我有一些PHP正在对网站上的API进行cURL调用,从而自动创建新用户帐户。当我提交表单时,PHP接管了,但是我收到一条错误消息:
TypeError:无法调用未定义(createUser#17)的方法“ trim”
我在代码中的任何地方都不会尝试使用一种称为“修剪”的方法,因此我不确定问题出在哪里。
这是我使用的代码,其中包含一些细节(已替换为xxxxx):
<?php
ini_set('display_errors', 1);
require_once("java/Java.inc");
// Assign form input values to variables.
$emailAddress=$_POST['emailAddress'];
$firstName=$_POST['firstName'];
$surname=$_POST['surname'];
$phoneNumber=$_POST['phoneNumber'];
// Initiate cURL.
$curl = curl_init();
$headers = array('Accept: application/json','Content-Type: application/json','appKey: xxxxxxxxxxxxxxxxx');
$postfields = array('fname'=>$firstName,'lname'=>$surname,'mobileNumber'=>$phoneNumber,'email'=>$emailAddress);
$fields_string = http_build_query($postfields);
// Setting up cURL.
curl_setopt($curl, CURLOPT_URL, 'xxxxxxxxxxxxxxxxx');
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); // Forces it to use HTTP/1.1
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, $fields_string);
// Execute cURL.
$response = curl_exec($curl);
// Display cURL response.
echo('Response: '.$response);
// Display error if POST fails.
if(curl_exec($curl) === false){
die('Error: "' . curl_error($curl) . '" - Code: ' . curl_errno($curl));
} else {
echo('Executed with no errors.');
};
if (!curl_errno($curl)) {
switch ($http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE)) {
case 200: # OK
break;
default:
echo ' Unexpected HTTP code: ', $http_code, "\n";
}
}
curl_close($curl);
?>