我有一个问题,我需要一些帮助。我有PHP版本4.4.7,我想在API中发布数据,这使用MVC模式和json数据。我尝试了get_file_contents方法,但我得到了405错误。
我想在下面的链接中传递三个变量
http:...../api/create_customer?x=test&y=test1&y=test3create_customer是我必须调用和传递属性的方法。为了连接凭据并将数据发送到API,此版本的PHP支持什么。升级版本的可能性是不可能的,所以我必须在当前版本中找到一种方法来升级。
发布于 2016-09-12 21:35:38
您可以使用curl。示例如下:
$content = json_encode($content);
$credentials = $userName。':‘。$password;
$options = array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_USERPWD => $credentials,
CURLOPT_HTTPHEADER => array('Content-type: application/json') ,
CURLOPT_POSTFIELDS => $content,
//Debug
//CURLOPT_VERBOSE => 1
);
$ch = curl_init($url);
curl_setopt_array($ch, $options);
$result = curl_exec($ch);https://stackoverflow.com/questions/39450487
复制相似问题