php查询数据返回xml,php – cURL返回XML或JSON

一旦人们注册,我将向他们发送一封电子邮件,其链接将允许他们编辑他们的详细信息(我知道这是一种疯狂的做事方式,但我正在研究其他人的代码所以不要介意)例如这样的网址http://example.com/palreg.php?paliD=1234,当他们转到该页面时,表单将填充他们的信息,以便他们可以进行更改.

现在问题是数据库在不同的站点,并且必须将信息传递到该站点以执行选择操作,为此我使用cURL发送信息,如此

$url = "http://example2.com/processXML.php";

$xmlStr will be like this

select

1234

$ch=curl_init();

curl_setopt($ch,CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_FAILONERROR, 1);

curl_setopt ($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);

curl_setopt ($ch, CURLOPT_POSTFIELDS, 'xmlstr='.$xmlStr);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$data = curl_exec($ch);

在另一端(http://example2.com/processXML.php)我将xml转换为数组并执行查询以根据发送的id选择pal信息.

现在真正的问题是如何将检索到的pal信息(如xml或json或数组)发送回来,以便我可以使用返回的数据填充表单.

我也可以返回$dataArray;在processXML.php并能够抓住它?

可以让事情更清楚,我在processXML.php中做的是

检索结果集并执行此操作

print json_encode($resultArray);

我不应该打印或返回

谢谢,如果事情不清楚,请告诉我.

解决方法:

只需按需要对其进行编码,然后将其回显到页面即可.你的$data =将包含回显的内容.个人偏好一直是使用JSON,因为它很容易丢弃.如在

//Bunch of DB stuff..

$row=mysql_fetch_however_you_handle_it();

echo json_encode($row);

//on your receiving end, that just did the cURL send,

$row=json_decode($data,true);//decode the JSON straight into an array...

标签:php,arrays,json,return,curl

来源: https://codeday.me/bug/20190730/1580121.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要使用curl命令进行POST请求发送XML文件,可以按照以下步骤进行操作: 1. 首先,将XML文件的内容保存到一个文件中,比如1.xml。 2. 然后,使用curl命令执行POST请求,并指定文件的路径作为数据参数。命令的格式如下: ``` cat 1.xml | curl -X POST -H 'Content-type:text/xml' -d @- http://1.1.1.1::8081/httpInvokeServlet ``` 这个命令会使用cat命令将1.xml文件的内容读取并通过管道传递给curl命令的-d参数。同时,通过-H参数指定请求头的Content-type为text/xml。 3. 替换命令中的1.xml为你实际的XML文件路径和文件名。 总结起来,使用curl命令发送POST请求并提交XML文件的步骤如下: 1. 将XML文件保存到一个文件中,比如1.xml。 2. 使用命令`cat 1.xml | curl -X POST -H 'Content-type:text/xml' -d @- http://1.1.1.1::8081/httpInvokeServlet`发送POST请求,并将文件内容作为数据参数传递给curl命令。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [curl模拟post json或post xml文件](https://blog.csdn.net/db9902943/article/details/101241250)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *3* [如何用Curl 来post xml 数据](https://blog.csdn.net/weixin_30872671/article/details/95253137)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值