zoukankan      html  css  js  c++  java
  • php模拟HTTP协议发送post请求方法

    今天用到php模拟http发送post请求记录

    代码如下:

    <?php
    $url = 'xxxx.com';
    $data = 'a=one&b=two';
    $data = urlencode($data);
    $ch = curl_init();//初始化
    curl_setopt($ch, CURLOPT_URL, $url);//抓取网页
    curl_setopt($ch, CURLOPT_POST, 1);//设置post
    curl_setopt($ch, CURLOPT_POSTFILES, $data);//post数据写入,全部数据使用HTTP协议中的"POST"操作来发送。要发送文件,在文件名前面加上@前缀并使用完整路径。这个参数可以通过urlencoded后的字符串类似'para1=val1&para2=val2&...'或使用一个以字段名为键值,字段数据为值的数组。如果value是一个数组,Content-Type头将会被设置成multipart/form-data。
    $re = curl_exec($ch);//执行cURL会话;
    curl_close($ch);//关闭会话,释放资源;
    ?>
  • 相关阅读:
    Day-5 python
    Day-2 python
    OCR技术浅探
    yael图像检索库
    编程语言
    BOW模型和SIFT特征
    汉明嵌入
    Lua1.1 Lua 的参考手册 (三)
    Lua1.1 Lua 的参考手册 (二)
    Lua1.1 Lua 的参考手册 (一)
  • 原文地址:https://www.cnblogs.com/lilili/p/5122689.html
Copyright © 2011-2022 走看看