Php uses Snoopy. class. php to make an httpgetpost request-PHP source code

Source: Internet
Author: User
0

Snoopy is a php class used to imitate the functions of a web browser. it can obtain webpage content and send forms.

The following are some of its features:

1. convenient webpage content capture
2. facilitate text capture on webpages (remove HTML code)
3. convenient webpage crawling
4. support for proxy hosts
5. supports basic user/password authentication modes
6. support for custom user agent, referer, cookies, and header content
7. support browser redirection and control steering depth
8. extend the link in the webpage to a high-quality url (default)
9. easy to submit data and get the return value
10. support for tracking HTML frameworks (added in v0.92)
11. Transfer cookies when redirection is supported

Php uses Snoopy. class. php for http get post requests

1. [Code]Get the specified url content using the get method
 Fetch ($ url); // Obtain all content echo $ snoopy-> results; // display the result // optional $ snoopy-> fetchtext // get the text content (remove the html code) $ snoopy-> fetchlinks // get the link $ snoopy-> fetchform // get the form?>
2. [Code]Form submission
 Submit ($ action, $ formvars); // $ formvars is the submitted array echo $ snoopy-> results; // obtain the result returned after the form is submitted. // optional values: $ snoopy-> submittext; // after the form is submitted, only the html-removed text is returned. $ snoopy-> submitlinks; // after submission, only the link is returned?> Camouflage ip address, camouflage browser
 Cookies ["PHPSESSID"] = 'fc0000b1918bd522cc863f000090e6fff7 '; // disguise sessionid $ snoopy-> agent = "(compatible; MSIE 4.01; MSN 2.5; AOL 4.0; Windows 98 )"; // camouflage browser $ snoopy-> referer = https://www.php1.cn/; // camouflage source page address http_referer $ snoopy-> rawheaders ["Pragma"] = "no-cache "; // cache http header information $ snoopy-> rawheaders ["X_FORWARDED_FOR"] = "127.0.0.101"; // disguise ip $ snoopy-> submit ($ action, $ formvars ); echo $ snoopy-> results; ?>
 Submit ($ submit_url, $ submit_vars); print $ snoopy-> results;?>
3. [Code]Use proxy
 proxy_host = "my.proxy.host";$snoopy->proxy_port = "8080";// set browser and referer:$snoopy->agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";$snoopy->referer = "http://www.jonasjohn.de/";// set some cookies:$snoopy->cookies["SessionID"] = '238472834723489';$snoopy->cookies["favoriteColor"] = "blue";// set an raw-header:$snoopy->rawheaders["Pragma"] = "no-cache";// set some internal variables:$snoopy->maxredirs = 2;$snoopy->offsiteok = false;$snoopy->expandlinks = false;// set username and password (optional)//$snoopy->user = "joe";snoopy->pass = "bloe";// fetch the text of the website www.google.com:if($snoopy->fetchtext("http://www.google.com")){ // other methods: fetch, fetchform, fetchlinks, submittext and submitlinks// response code: print "response code: ".$snoopy->response_code."
\n";// print the headers: print "Headers:
";while(list($key,$val) = each($snoopy->headers)){ print $key.": ".$val."
\n";} print "
\n";// print the texts of the website: print "
".htmlspecialchars($snoopy->results)."
\n";}else{ print "Snoopy: error while fetching document: ".$snoopy->error."\n"; }?>

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.