PHP CURL模拟客户端浏览器的form提交请求 PHP模拟访客提交数据
对于一些需要在浏览器端通过from post提交的数据,其实我们可以用curl来模拟提交,可以参考下面案例
<?php $data = array("domain" => "bnxb.com", "source" => "webcc-xxx"); // POST data included in your query $ch = curl_init("https://my.webnic.cc/jsp/pn_qry.jsp"); // Set url to query curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); // Send via POST curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); // Set POST data curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return response text curl_setopt($ch, CURLOPT_HEADER, "Content-Type: application/x-www-form-urlencoded"); // send POST data as form data $response = curl_exec($ch); curl_close($ch); print_r($response); ?>
这是一个域名注册商的API接口,原始文档是通过html的from提交数据,这里改成用PHP CURL提交
顶(0)
踩(0)
- 最新评论