php 利用curl发送post请求

利用curl发送post请求完成数据,接口的访问,这里面的参数可以修正一下,就可以写成可以支持文件上传的一个post请求,但是我这里不做仔细的写了.等以后有时间了在考虑怎么分解这个方法:

/**

* Curl版本

* 使用方法:

* $post_string = "app=request&version=beta";

* request_by_curl(‘http://blog.snsgou.com/restServer.php‘, $post_string);

*/

function request_by_curl($remote_server, $post_string) {

$ch = curl_init ();

curl_setopt ( $ch, CURLOPT_URL, $remote_server );

curl_setopt ( $ch, CURLOPT_POSTFIELDS, $post_string );

curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, true );

curl_setopt ( $ch, CURLOPT_USERAGENT, "snsgou.com‘s CURL Example beta");

$data = curl_exec ( $ch );

curl_close ( $ch );

return $data;

}

时间: 2024-08-24 02:12:17

php 利用curl发送post请求的相关文章

每天一个linux命令13之curl发送http请求

一.get请求 curl "http://www.baidu.com"  如果这里的URL指向的是一个文件或者一幅图都可以直接下载到本地 curl -i "http://www.baidu.com"  显示全部信息 curl -l "http://www.baidu.com" 只显示头部信息 curl -v "http://www.baidu.com" 显示get请求全过程解析 wget "http://www.ba

CURL发送HTTP请求

<span style="font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: rgb(255, 255, 255);">1.</span><span style="font-size: 12px; background-color: rgb(255, 255, 255); font-family: Verdana, Geneva, Arial,

linux shell中curl 发送post请求json格式问题

今天在linux中使用curl发送一个post请求时,带有json的数据,在发送时发现json中的变量没有解析出来 如下 curl -i -X POST -H 'Content-type':'application/json' -d {"BTime":""$btime""} http://api.baidu.com 变量没有做解析 原来在shell中,"" '还是有很大区别的, 把修改后的curl发送贴出 atime=`dat

bat curl 发送http请求 监控网站

@echo off color 1f title 正在监控 www.0579ld.com.cn echo 正在监控 www.0579ld.com.cn(23.247.53.3).. :aaa D:\curl\curl -I www.0579ld.com.cn>nul set str=%ERRORLEVEL% if not "%str%"=="0" ( echo 在%date% %time:~0,5% 无法正常访问,重启中... :: cd c:\server\

关于在php中使用curl发送get请求时参数传递问题的解析

get请求是最简单的请求,不过要注意自己的请求是http请求还是https的请求,因为https请求时要关闭SSL验证,不然验证通不过,没有办法请求到数据. GET请求的参数 get传递参数和正常请求url传递参数的方式一样 1 function get_info($card){ 2 $url ="http://www.sdt.com/api/White/CardInfo?cardNo=".$bank_card; 3 $ch = curl_init(); 4 //设置选项,包括URL

curl 发送 http请求

测试接口,经常会用到接口测试工具如postman,而curl命令可以直接在终端进行测试,下面介绍一下如何使用 get 请求 curl "http://localhost:3000/api/books?page=1&limit=4" post请求 curl -X POST "http://localhost:3000/api/books"  -d "name=测试" -X POST 表示请求方式,-d 后边是请求参数 ,put.delete

Java利用HttpURLConnection发送post请求

URL url = null; HttpURLConnection http = null; try { url = new URL(urls); http = (HttpURLConnection) url.openConnection(); http.setDoInput(true); http.setDoOutput(true); http.setUseCaches(false); http.setConnectTimeout(50000);//设置连接超时 //如果在建立连接之前超时期满

php 中使用cURL发送get/post请求,上传图片,批处理

cURL是利用url语法规定传输文件和数据的工具.php中有curl拓展,一般用来实现网络抓取,模拟发送get   post请求,文件上传. 在php中建立curl的基本步骤如下: 1 初始化        2 设置选项,包括url        3  执行并获取结果   4 释放curl句柄. 在工作和学习中,我也是时常用的curl.由于在使用curl设置选项时,各种选项比较难以记忆,需要参考,故在此记录下常用的一些例子,以便后来参考. 实例一 : 抓取网页数据(以拉手网开放api为例,也是g

使用PHP中的curl发送请求

使用CURL发送请求的基本流程 使用CURL的PHP扩展完成一个HTTP请求的发送一般有以下几个步骤: 初始化连接句柄: 设置CURL选项: 执行并获取结果: 释放VURL连接句柄. 下面的程序片段是使用CURL发送HTTP的典型过程 // 1. 初始化 $ch = curl_init(); // 2. 设置选项,包括URL curl_setopt($ch,CURLOPT_URL,"http://www.devdo.net"); curl_setopt($ch,CURLOPT_RETU