$host = array("Host: act.qzone.qq.com");// 域名不帶http://
$data = array(
            'aa' => 'xx',
            'bb'=>'xx'
        );     
$url = 'http://127.0.0.1/xxx/xxx/api/';
var_dump( $this->curl_post($host, $data,$url) );

function curl_post($host,$data,$url)
{
   $ch = curl_init();
   $res= curl_setopt ($ch, CURLOPT_URL,$url);
   curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
   curl_setopt ($ch, CURLOPT_HEADER, 0);
   curl_setopt($ch, CURLOPT_POST, 1);
   curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
   curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($ch,CURLOPT_HTTPHEADER,$host);
   $handles = curl_exec($ch);
   curl_close($ch);
   return $handles;
}
function postData($url, $post)
{
    $ch = curl_init();
    $timeout = 300;
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //使用php curl获取页面内容或提交数据, 有时候希望返回的内容作为变量储存, 而不是直接输出
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);//在发起连接前等待的时间,如果设置为0,则无限等待。
    $handles = curl_exec($ch);
    curl_close($ch);
    return $handles;
}

提交json 數據
function postData($url, $post)
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'Content-Type:application/json',
            'Content-Length:'.strlen($post))
        );
        $handles = curl_exec($ch);
        curl_close($ch);
        return $handles;
    }

刪除請求

$url='********************';
$this->postData($url);

private function postData($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, "guest:unknow44");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, DELETE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type:application/json')
);
$handles = curl_exec($ch);
curl_close($ch);
return $handles;
}

PHP CURL header 设置HOST主机头进行访问并 POST提交數據的更多相关文章

  1. 【转】PHP curl CURLOPT_HTTPHEADER设置HOST

    为了安全,我们的web服务主机往往不能上网.维护的时候,也是通过跳板机,ssh登录后去操作. 有时候我们的程序需要访问外网.比如需要调用外网其他程序的某个接口.这下该怎么办呢? 我们可以通过PHP的C ...

  2. php curl如何设置自定义请求头和打印请求头信息

    $header = [ 'client:h5', 'token:test', ]; curlRequest($url, $params, true, 10, $header); PHP5.1.3版以上 ...

  3. iis 设置 主机头,设置 host文件

    iis主机头设置后,一般本机不能再用ip:127.0.0.1访问. 接着设置host文件,使用域名直接访问主机头就可以访问到127.0.0.1 host文件路径:c//system32/drives/ ...

  4. [转]php curl 设置host curl_setopt CURLOPT_HTTPHEADER 指定host

    From : http://digdeeply.org/archives/10132139.html 我们在开发测试时,有时web服务器会绑定一个域名,但是因为dns是无法解析的,我们需要设置host ...

  5. PHP header函数设置http报文头示例详解以及解决http返回头中content-length与Transfer-Encoding: chunked的问题

    最近在服务器上,多媒体与设备(摄像头)对接的时候,总是发生错误导致设备崩溃,抓包发现响应头不对,没有返回length,使得摄像头立即崩溃.找了一下资料,改了一下响应头就好了. //定义编码 heade ...

  6. golang中设置Host Header的小Tips

    前言 笔者最近时间一直在学习和写Ruby和Go,尤其是Go,作为云计算时代的标准语言,写起来还是相当有感觉的,难过其会越来越火. 不过写的过程中,也遇到了一些小问题,本文就是分享关于go语言设置 HT ...

  7. PHP header函数设置http报文头示例详解

    //定义编码 header( 'Content-Type:text/html;charset=utf-8 '); //Atom header('Content-type: application/at ...

  8. php curl header头

    工作中第一次用到header做个记录 工作中需要在heaer里面加上 Authorization 用来验证身份 public function index() { $url = "http: ...

  9. win7凭据管理、win7多用户远程登录、主机头设置、nuget.org无法访问

    前言  最近遇到的几个问题,然后处理在此对处理方式进行记录一下. 1.服务器共享文件夹,在本机进行访问登录时,每次登录或者每次开机进入都要进行登录的权限认证,这样很麻烦. 2.服务器难免会有多用户同时 ...

随机推荐

  1. Java开发系列-JDBC

    概述 JDBC(Java DataBase Connectivity,java数据库连接)是一种用于执行SQL语句的Java API,可以为多种关系数据库提供统一访问,它由一组用Java语言编写的类和 ...

  2. linux 系统优化初始化配置

    一.系统优化配置 1.修改yum源  配置国内yum源 阿里云yum源地址 #CentOS 5.x wget -O /etc/yum.repos.d/CentOS-Base.repo http://m ...

  3. sql中on的连接条件与where的区别

    left join [表名] on [条件] where [条件] --on表示连接条件 --where表示对结果的过滤条件 两者不尽相同,使用时需注意 例如: select * from  tabl ...

  4. Android基础控件RatingBar星级评分条的使用

    1.简介 RatingBar继承ProgressBar,除了ProgressBar的属性外还有特有属性: android:isIndicator:是否用作指示,用户无法更改,默认false andro ...

  5. java中 &&与& ||与| 的区别

    public class Demo { public static void main(String[] args) { int i = 5; int j = 3; // || 与 | 的区别 boo ...

  6. jdom xpath定位带xmlns命名空间的节点(转)

    jdom xpath定位带xmlns命名空间的节点 2013-06-29      0个评论       作者:baozhengw 收藏    我要投稿 关键词:jdom xpath xmlns 命名 ...

  7. pandas一些基本操作(DataFram和Series)_4

    import numpy as np;import pandas as pd;kill_num=pd.Series([10,12,8,5,0,2,6])#击杀数量#青铜1200-2000#白银2001 ...

  8. for update行级锁的作用

    1.for update叫排它锁,是一种行级锁,一旦用户对某个行施加了行级加锁,则该用户可以查询也可以更新被加锁的数据行,其它用户只能查询但不能更新被加锁的数据行.如果其它用户想更新该表中的数据行,则 ...

  9. 深度学习(二十六)Network In Network学习笔记

    深度学习(二十六)Network In Network学习笔记 Network In Network学习笔记 原文地址:http://blog.csdn.net/hjimce/article/deta ...

  10. 【心无旁骛】vue-ts-daily

    这是一个非常有意思的项目,我们先来看看效果 这个项目所用的技术也比较有意思,它的技术栈为vue2.5 + Typescript + vuex + vue-router 放下博主的项目地址吧,https ...