简体   繁体   中英

how to send post request by curl to web services in php

I need to fetch data from myallocator.com. I have his api address api.myallocator.com, but when I send my data to them, it failed. I wrote some code for that which is shown below. Basically that pms property management system site.By that you can manage your property with his api.

    $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);

Here Is the example of php curl with post try this

        <?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 { ... }

        ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM