我需要在客户端和服务器端(php)验证一些表单数据。我可以使用一些API web服务来检查数据表单。问题是:我可以在客户端使用Ajax调用和我的API web服务验证数据。如何从服务器端使用API web服务?
发布于 2015-05-24 17:36:33
您可以使用目录调用外部调用
$homepage = file_get_contents('http://www.example.com/');
在那里您可以从url本身发送参数,
在这里,向api发送参数的示例
构造一个数组,并将要验证的值放置在
$getdata = http_build_query(
array(
'name' => 'Francesco',
'phone' => '2434343',
'age'=>'23',
'city'=>'MA',
'state'=>'US'
)
);
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $getdata
)
);
$context = stream_context_create($opts);
然后直接发送到你的api
file_get_contents('http://example.com/send.php?'.$getdata, false, $context);
https://stackoverflow.com/questions/30426162
复制相似问题