首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何通过curl向php中的web服务发送post请求

如何通过curl向php中的web服务发送post请求
EN

Stack Overflow用户
提问于 2014-05-28 13:04:18
回答 1查看 1.1K关注 0票数 0

我需要从myallocator.com获取数据。我有他的api地址api.myallocator.com,但是当我把我的数据发送给他们时,它失败了。我为此编写了一些代码,如下所示。基本上就是pms物业管理系统site.By,你可以用他的api来管理你的物业。

代码语言:javascript
复制
    $url = "http://api.myallocator.com/";

    $xmlRequestString='<?xml version="1.0" encoding="UTF-8"?>
    <GetProperties>
      <Auth>
        <UserId>"xxxxxxx"</UserId>
        <UserPassword>"xxxxx"</UserPassword>
        <VendorId>"xxxxxxx"</VendorId>
        <VendorPassword>"xxxxxxxx"</VendorPassword>
      </Auth>
    </GetProperties>';

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_POSTFIELDS,  $xmlRequestString);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_VERBOSE, 0);
    $data = curl_exec($ch);
    echo $data;
    curl_close($ch);
EN

回答 1

Stack Overflow用户

发布于 2014-05-28 13:38:03

下面是php curl和post try this的示例

代码语言:javascript
复制
        <?php
        $ch = curl_init();            
        // set your site url
        curl_setopt($ch, CURLOPT_URL,"http://testmysite.com/");

        curl_setopt($ch, CURLOPT_POST, 1);
        // postvar1, postvar2 .. are the parameters to send with post
        curl_setopt($ch, CURLOPT_POSTFIELDS,
                    "postvar1=value1&postvar2=value2&postvar3=value3");          
        // receive server response ...
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

        $server_output = curl_exec ($ch);            
        curl_close ($ch);

        if ($server_output == "OK") { ... } else { ... }

        ?>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23903164

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档