Php post simulation steps

Source: Internet
Author: User
Php post simulation method PHP actively POST data to JSP which method is better? It is best to have an example. thank you ------ solution ---------------- which is the most commonly used curl module in the background simulation ------ solution ------------------ PHPcodefunctionpost_url ($ url, $ post & quot; & quo php post simulation method

PHP actively POST data to JSP

Which method is better?

It is best to have an example. thank you.

------ Solution --------------------
Which of the most common curl modules is simulated in the background?
------ Solution --------------------
PHP code
Function post_url ($ url, $ post = "", $ host = "www.ydtuiguang.com", $ referrer =' http://www.ydtuiguang.com/ ', $ Proxy =-1) {if (function_exists ("curl_init") {$ ch = @ curl_init (); @ curl_setopt ($ ch, CURLOPT_URL, $ url ); if (! Empty ($ proxy ["address"]) @ curl_setopt ($ ch, CURLOPT_PROXY, strpos ($ proxy ["address"], "http") === 0? $ Proxy ["address"]: "http: //". $ proxy ["address"]); if (! Empty ($ proxy ["account"]) &! Empty ($ proxy ["password"]) @ curl_setopt ($ ch, CURLOPT_PROXYUSERPWD, $ proxy ["account"]. ":". $ proxy ["password"]); @ curl_setopt ($ ch, CURLOPT_REFERER, $ referrer); @ curl_setopt ($ ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 7.0; windows NT 5.0) "); @ curl_setopt ($ ch, recipe, COOKIE_FILE_PATH); @ curl_setopt ($ ch, CURLOPT_COOKIEFILE, COOKIE_FILE_PATH); @ curl_setopt ($ ch, CURLOPT_HEADER, 0 ); @ Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1); @ curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, 1); @ curl_setopt ($ ch, CURLOPT_TIMEOUT, 1000); if (! Empty ($ post) {@ curl_setopt ($ ch, CURLOPT_POST, 1); @ curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ post );} $ result = @ curl_exec ($ ch); @ curl_close ($ ch);} elseif (function_exists ("fsockopen") {$ httpheader = "POST ". $ url. "HTTP/1.1 \ r \ n"; $ httpheader. = "Accept: */* \ r \ n"; $ httpheader. = "Accept-Language: zh-cn \ r \ n"; $ httpheader. = "Referer :". $ referrer. "\ r \ n"; $ httpheader. = "Content-Type: application/x-www-f Orm-urlencoded \ r \ n "; $ httpheader. = "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1) \ r \ n"; $ httpheader. = "Host :". $ host. "\ r \ n"; $ httpheader. = "Content-Length :". strlen ($ post ). "\ r \ n"; $ httpheader. = "Connection: Keep-Alive \ r \ n"; $ httpheader. = "\ r \ n"; $ httpheader. = $ post; $ fd = fsockopen ($ host, 80); fwrite ($ fd, $ httpheader); $ result = ""; while (! Feof ($ fd) {$ result. = fread ($ fd, 8192);} fclose ($ fd);} elseif (function_existes ('File _ get_contents ') {$ httpheader = "POST ". $ url. "HTTP/1.1 \ r \ n"; $ httpheader. = "Accept: */* \ r \ n"; $ httpheader. = "Accept-Language: zh-cn \ r \ n"; $ httpheader. = "Referer :". $ referrer. "\ r \ n"; $ httpheader. = "Content-Type: application/x-www-form-urlencoded \ r \ n"; $ httpheader. = "User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1) \ r \ n"; $ httpheader. = "Host :". $ host. "\ r \ n"; $ httpheader. = "Content-Length :". strlen ($ post ). "\ r \ n"; $ httpheader. = "Connection: Keep-Alive \ r \ n"; $ opts = array ('http' => array ('method' => "POST ", 'header' => $ httpheader, 'content' => $ post); $ context = stream_context_create ($ opts); $ result = file_get_contents ($ url, 'R ', $ context);} return $ result ;}
------ Solution --------------------
Discussion

Which of the most common curl modules is simulated in the background?

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.