简体   繁体   English

发送带有空响应的POST请求

[英]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. 我试图通过CURL从我的API获得响应,该方法需要通过XML获取用户数据,然后返回带有响应数据的XML。 I get nothing back. 我什么也没回来。 API works well, when I try the same request elsewhere than in PHP, it works. API运作良好,当我在PHP以外的其他地方尝试相同的请求时,它会运作。 My API requires the data to be sent in application/xml Content-Type. 我的API要求将数据发送到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. 这将输出未转义的XML。 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. 您的浏览器将不会在浏览器窗口内显示任何内容,但是您可以在查看页面源代码时看到一些内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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