PHP Curl Analog POST request submission Data _php Tutorial

Source: Internet
Author: User
   recently in the campus library book information collection procedures, since it is the collection of library books, there must be submitted search page, nothing but post submission, let me think of the curl simulation submission, first through the Firebug to capture the packet query after post submission format as follows:

txtWxlx=CN&hidWxlx=spanCNLx&txtPY=HZ&txtTm=%D2%F4%C0%D6&txtLx=%25&txtSearchType=1&nMaxCount=100&nSetPageSize=10&cSortFld=%D5%FD%CC%E2%C3%FB&B1=%BC%EC+%CB%F7;搜索的关键字name=txtTm,随后代码如下:

 Php$keyword= "Music";$post= "txtwxlx=cn&hidwxlx=spancnlx&txtpy=hz&txttm={$keyword}&txtlx=%25&txtsearchtype=1&nmaxcount=100&nsetpagesize=20&csortfld=%d5%fd%cc%e2%c3%fb& B1=%bc%ec+%cb%f7 ";$url= "Http://210.30.68.130/wxjs/tmjs.asp";//Enquiry Address$ch=curl_init (); curl_setopt ($ch, Curlopt_referer, "http://210.30.68.130/wxjs/tmjs_form.asp/");//Analog Sourcescurl_setopt ($ch, Curlopt_url,$url);//URLcurl_setopt ($ch, curlopt_followlocation,1); curl_setopt ($ch, Curlopt_header,false); curl_setopt ($ch, Curlopt_post, 1);//Analog Postcurl_setopt ($ch, Curlopt_postfields,$post);//Post ContentCurl_exec ($ch); $output= Curl_close ($ch); Echo $output; ?>

But the returned page always shows no related content, if the keyword changed to English or the number can be normal display, so think that this should be a coding problem, and then on the post can see Txttm=%d2%f4%c0%d6 through the query that this is URL encoding, Chinese characters will be converted, If there is no change in English, then the head information is also added to the following:

$header Array (); $header [] = ' user-agent:mozilla/5.0 (Windows NT 6.1; rv:30.0) gecko/20100101 firefox/30.0 '; $header [] = ' accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 '; $header [] = ' connection:keep-alive '; $header [] = ' content-type:application/x-www-form-urlencoded '$ch$header

In fact, mainly $header[] = ' content-type:application/x-www-form-urlencoded '; After loading the page again if it is a Chinese character display or there is no relevant content, then think of a very simple problem, PHP program is UTF8, but the library's website is gb2312, OK, plus a sentence, $keyword = iconv (' UTF-8 ', ' GB2312 ', $keyword); Load again, this should be the key to the problem, Then I delete the head information after adding a sentence $keyword = UrlEncode ($keyword); Load again is the following code:

 Php$keyword= "World";$keyword=Iconv(' UTF-8 ', ' GB2312 ',$keyword);$keyword=UrlEncode($keyword);$post= "txtwxlx=cn&hidwxlx=spancnlx&txtpy=hz&txttm={$keyword}&txtlx=%25&txtsearchtype=1&nmaxcount=100&nsetpagesize=20&csortfld=%d5%fd%cc%e2%c3%fb& B1=%bc%ec+%cb%f7 ";$url= "Http://210.30.68.130/wxjs/tmjs.asp";//Enquiry Address$ch=curl_init (); curl_setopt ($ch, Curlopt_referer, "http://210.30.68.130/wxjs/tmjs_form.asp/");//Analog Sourcescurl_setopt ($ch, Curlopt_url,$url);//URLcurl_setopt ($ch, curlopt_followlocation,1); curl_setopt ($ch, Curlopt_header,false); curl_setopt ($ch, Curlopt_post, 1);//Analog Postcurl_setopt ($ch, Curlopt_postfields,$post);//Post ContentCurl_exec ($ch); $output= Curl_close ($ch); Echo $output; ?>

As expected, the normal display, followed by the page content of the collection and typesetting problems. It's just a regular. (Because the campus network can only be accessed by our intranet)

http://www.bkjia.com/PHPjc/819719.html www.bkjia.com true http://www.bkjia.com/PHPjc/819719.html techarticle recently in the School library book information collection procedures, since it is the collection of library books, there must be a submission search page, nothing but post submission, let me think of the curl simulation submitted, ...

  • 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.