How does APIphp of No. 1 store send an http request and obtain the returned XML

Source: Internet
Author: User
It is known that the APIphp of No. 1 stores has APIs for sending http requests and obtaining the returned XML for guidance. it is OK according to the interface specifications. the methods generally include: file_get_contents, curl, which method does fsockopen use? depends on your API and the specific environment in which you know the API of No. 1 store. how does php send an http request and obtain the returned XML?
Please advise

------ Solution --------------------
If all the APIs are available, it will be okay according to the interface specifications.

Methods generally include: file_get_contents, curl, and fsockopen.

Which one to choose depends on your API and specific environment?


Your problem description is almost 0, which is not a good way to ask questions.
------ Solution --------------------
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
------ Solution --------------------
Discussion

Reference:

If all the APIs are available, it will be okay according to the interface specifications.

Methods generally include: file_get_contents, curl, and fsockopen.

Which one to choose depends on your API and specific environment?


Your problem description is almost 0, which is not a good way to ask questions.


Well, the value returned by their API is file_get_contents of xml. the Function reads the content.

------ Solution --------------------
Now that all the content is available, you can study the rest of the process by yourself.
Php parses xml

Believe in yourself, no problem
------ Solution --------------------
Discussion

Reference:

Isn't that what we get? What else do you want?

I want to get XML, which only contains content. let's see how to read the tag.

------ Solution --------------------
Discussion

Reference:

Reference:

Isn't that what we get? What else do you want?

I want to get XML, which only contains content. let's see how to read the tag.


Yes These should also be read out. all the code returns are content numbers.

------ Solution --------------------
Use simplexml to parse the data into an array. the key of the array is the tag you want.
------ Solution --------------------
Domdocument and simplexml are both official libraries. write a function to recursively traverse it.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.