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

WBOY
Libérer: 2016-06-13 10:33:42
original
875 Les gens l'ont consulté

已知一号店的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>
Copier après la connexion
探讨

引用:

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

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

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


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


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

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

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

引用:

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

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

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

引用:

引用:

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

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


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

------解决方案--------------------
用simplexml解析成数组,数组的键就是你要的标签
------解决方案--------------------
domdocument和simplexml都是官方库,写个函数递归遍历一下就可以了。
Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!