Heim  >  Artikel  >  Backend-Entwicklung  >  已知一号店的API php怎么发送http请求并获取返回的XML

已知一号店的API php怎么发送http请求并获取返回的XML

WBOY
WBOYOriginal
2016-06-13 10:33:42872Durchsuche

已知一号店的API php如何发送http请求并获取返回的XML
求指点

------解决方案--------------------
都有API了,就按照接口规范就ok了啊

方法一般都有: file_get_contents,curl,fsockopen

具体选用哪一种,要看你的API和具体使用环境了


你的问题描述几乎为0,可不是好的提问方式哟
------解决方案--------------------

JScript code
<script>//Ajaxvar xmlHttp;    function createXMLHttpRequest() {        if(window.XMLHttpRequest) {            xmlHttp = new XMLHttpRequest();        } else if (window.ActiveXObject) {            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");        }    }        createXMLHttpRequest();                //API接口        url = "xxx.php?param="+param+"&ran="+Math.random();        method = "GET";        xmlHttp.open(method,url,true);        xmlHttp.onreadystatechange = show;        xmlHttp.send(null);    }    function show(){        if (xmlHttp.readyState == 4){            if (xmlHttp.status == 200){                var text = xmlHttp.responseText;                                alert("xml-->>"+text);                //document.getElementById("s2").innerHTML = text;            }else {                alert("response error code:"+xmlHttp.status);            }        }    }</script><br><font color="#e78608">------解决方案--------------------</font><br>
探讨

引用:

都有API了,就按照接口规范就ok了啊

方法一般都有: file_get_contents,curl,fsockopen

具体选用哪一种,要看你的API和具体使用环境了


你的问题描述几乎为0,可不是好的提问方式哟


嗯 他们API返回的值是 xml的 file_get_contents 这个函数读取的是内容

------解决方案--------------------
既然都得到内容了,剩下的过程还是自己研究学习下吧
php解析xml的方法网上一抓一大把

相信自己,没问题的
------解决方案--------------------
探讨

引用:

这不是得到了吗? 还想干什么?

我是想 得到XML 这个只有内容,看看怎么把标签也读出来

------解决方案--------------------
探讨

引用:

引用:

这不是得到了吗? 还想干什么?

我是想 得到XML 这个只有内容,看看怎么把标签也读出来


就是这些也要读出来 我现在的代码 返回的 全部是 内容 数字

------解决方案--------------------
用simplexml解析成数组,数组的键就是你要的标签
------解决方案--------------------
domdocument和simplexml都是官方库,写个函数递归遍历一下就可以了。
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn