How to solve the phppost request

Source: Internet
Author: User
How to submit a post request for a phppost request in php? I want to request a URL and pass the parameters in. It returns the results of an xml file. Post in php ., Function_xpost ($ url, $ p) {$ f = ''; $ data =''; foreach ($ pas $ k = & gt; $ v) {$ data. = php post request
In php, how do I submit a post request? I need to request a URL and input parameters. It returns the results of an xml file. Post in php.

------ Solution --------------------
Function _ xpost ($ url, $ p)
{
$ F = '';
$ Data = '';
Foreach ($ p as $ k => $ v)
{
$ Data. = $ f. $ k. '='. urlencode ($ v );
$ F = '&';
}

$ Curl = curl_init ($ url );
Curl_setopt ($ curl, CURLOPT_SSL_VERIFYHOST, 1 );
Curl_setopt ($ curl, CURLOPT_SSL_VERIFYPEER, false );
Curl_setopt ($ curl, CURLOPT_RETURNTRANSFER, 1 );
Curl_setopt ($ curl, CURLOPT_POST, 1 );
Curl_setopt ($ curl, CURLOPT_POSTFIELDS, $ data );
$ Res = curl_exec ($ curl );

If (curl_errno ($ curl ))
{
Echo 'curl error: '. curl_error ($ Curl );
}
Curl_close ($ curl );
Return $ res;
}

$ X = _ xpost ('http: // abc.com/aa.php', array ('username' => $ uname,
));
------ Solution --------------------
Use curl on the first floor
------ Solution --------------------
Use simplexml to parse xml. after learning simplexml, you don't need to worry about xml.

Discussion

For more information, see $ x = _ xpost ('http: // abc.com/aa.php', array ('username' => $ uname). the received data is an xml file:


1

How can I get Between 1?

------ Solution --------------------
A simple regex,
Preg_match ('/ (.*?) <\/Response>/S', $ xml, $ m );
Echo $ m [1];
------ Solution --------------------
Discussion

For more information, see $ x = _ xpost ('http: // abc.com/aa.php', array ('username' => $ uname). the received data is an xml file:


1

How can I get Between 1?

------ Solution --------------------
Simplexml
------ Solution --------------------
Strong regular expressions on the top 6 floors

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.