简体   繁体   中英

Send POST request with empty response

I am trying to get response form my API via CURL, the method needs to get user data via XML and than returns XML with response data. I get nothing back. API works well, when I try the same request elsewhere than in PHP, it works. My API requires the data to be sent in application/xml Content-Type.

Any ideas what I am doing wrong?

<?php
    $request="https://api.mydomain.com/operation/v1/rest/xml/user/authenticate";
    $xml_data='<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
               <userCredentials>
                    <userName>name</userName>
                    <password>password</password>
               </userCredentials>';

    $ch = curl_init();
    //curl_setopt($ch, CURLOPT_MUTE, 1);
    curl_setopt($ch, CURLOPT_URL, $request);
    //curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, "Content-type: application/xml");
    curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($ch);
    curl_close($ch);

    echo "<b>Request:</b> $request <br/>";
    echo "<b>Response:</b><pre>".$output."</pre>";
?>

As commented, quick guess (lengthy comment):

echo "<b>Response:</b><pre>".$output."</pre>";

This will output the XML unescaped. Your browser will not display anything inside the browser window, but you should be fine to see something when you view the source of the page.

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