PHP Curl Simulation answer, always 400 exception

Source: Internet
Author: User
PHP Curl Simulation answer, always 400 error
I want to simulate this site's answer: http://zsjs.kaiwind.com/kf/html/index.html
He is landing on the above page, then to the new page to answer questions, the answer is all finished and actually, allow the submission.
He is the AJAX submission, all JS authentication passed, back to the background to send AJAX requests, complete the page.

He sent the data is not complex, but in the simulation of his data sent, but always error, the following posted code and error prompts, hope that the great God to save.
Code:
Curl Request section:
 function Vget ($url, $header = null) {//Impersonation get Content function
Global $browsers;
$curl = Curl_init ();//Start a Curl session
curl_setopt ($curl, Curlopt_url, $url);//Address to access
curl_setopt ($curl, Curlopt_httpheader, $browsers);//Set HTTP header
curl_setopt ($curl, Curlopt_ssl_verifypeer, 0);//Check the origin of the certification certificate
curl_setopt ($curl, Curlopt_ssl_verifyhost, 1);//Check whether the SSL encryption algorithm exists from the certificate
curl_setopt ($curl, curlopt_useragent, $_server[' http_user_agent ');//browser used by the impersonated user
curl_setopt ($curl, Curlopt_referer, ' HTTP://www.baidu.com ');
curl_setopt ($curl, curlopt_followlocation, 1);//use auto-jump
curl_setopt ($curl, Curlopt_autoreferer, 1);//Auto Set Referer
curl_setopt ($curl, Curlopt_httpget, 1);//Send a regular GET request
curl_setopt ($curl, Curlopt_cookiejar, $GLOBALS [' cookie_file ']);//Save Cookie File
if (Isset ($header) &&!is_null ($header)) {
curl_setopt ($curl, Curlopt_httpheader, $header);//Where to set the header information
}
curl_setopt ($curl, Curlopt_header, true);
curl_setopt ($curl, Curlopt_timeout, 30);//Set timeout limit to prevent dead loops
curl_setopt ($curl, Curlopt_header, 0);//Displays the contents of the HEADER area returned
curl_setopt ($curl, Curlopt_returntransfer, 1);//The information obtained is returned in the form of a file stream
$tmpInfo = curl_exec ($curl);//Perform operation
if (Curl_errno ($curl)) {
Echo ' Errno '. Curl_error ($curl);
}
Curl_close ($curl);//Turn off Curl session
return $tmpInfo;//returns data
}

function vpost ($url, $data) {//analog commit data functions
Global $browsers;
$header = "content-type:application/x-www-form-urlencoded";//define Content-type as XML
$curl = Curl_init (); Start a Curl session
curl_setopt ($curl, Curlopt_url, $url); The address to be accessed
curl_setopt ($curl, Curlopt_ssl_verifypeer, 0); Examination of the source of the certification certificate
curl_setopt ($curl, Curlopt_httpheader, $browsers);//Set HTTP header
curl_setopt ($curl, Curlopt_ssl_verifyhost, 1); Check that the SSL encryption algorithm exists from the certificate
curl_setopt ($curl, curlopt_useragent, $_server[' http_user_agent '); Simulating the browser used by the user
curl_setopt ($curl, curlopt_followlocation, 1); Use Auto Jump
curl_setopt ($curl, Curlopt_referer, ' http://zsjs.kaiwind.com/kf/html/question.html?15238132836?10 ');
curl_setopt ($curl, Curlopt_autoreferer, 1); Set Referer automatically
curl_setopt ($curl, Curlopt_post, 1); Send a regular POST request
curl_setopt ($curl, Curlopt_postfields, $data); Post-Submitted packets
curl_setopt ($curl, Curlopt_cookiefile, $GLOBALS [' cookie_file ']); Read the cookie information stored above
curl_setopt ($curl, Curlopt_timeout, 30); Setting a timeout limit to prevent a dead loop
curl_setopt ($curl, Curlopt_header, 0); Displays the contents of the header area returned
curl_setopt ($curl, Curlopt_returntransfer, 1); Gets the information returned as a file stream
$tmpInfo = curl_exec ($curl); Perform actions
if (Curl_errno ($curl)) {
Echo ' Errno '. Curl_error ($curl);
}
Curl_close ($curl); Critical Curl Session
return $tmpInfo; Return data
}

Executive section:
"!--? php
header (' content-type:text/html;charset=utf-8 ');
$phone = ' 15238132836 ';
$area = ' 10 ';
$cookie _jar = Tempnam ('./', ' cookie ');//Specify the location of the cookie file where the SessionID is saved

$data = Array (
' Tel ' =>urlencode ($ Phone),
' area ' =>urlencode ($area)
);

$GLOBALS [' cookie_file '] = $cookie _jar;
require_once ('./functions.php ');
$url = ' http://zsjs.kaiwind.com/kf/html/index.html ';
//Vget ($url);
  • 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.