已知一号店的API php如何发送http请求并获取返回的XML
求指点
------解决方案--------------------
都有API了,就按照接口规范就ok了啊
方法一般都有: file_get_contents,curl,fsockopen
具体选用哪一种,要看你的API和具体使用环境了
你的问题描述几乎为0,可不是好的提问方式哟
------解决方案--------------------
<script>
//Ajax
var 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>
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号