ajax跨域真的很难用,去google看看吧。使用 ajax 在您的服务器中调用 .php 并使用 curl post。
我英语不好所以
创建对 ajax.php 的调用 GET 并在 ajax.php 中写入。
echo GETrequest("http://www.w3schools.com/");
这是我的 2 curl 函数,只需更改结束行, $this->data 即可返回
private function GETrequest($link){
$zapytanie = curl_init(); // adres strony
curl_setopt($zapytanie, CURLOPT_URL, $link);
curl_setopt($zapytanie, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.4) Gecko/20091030 Gentoo Firefox/3.5.4"); // useragent
curl_setopt($zapytanie, CURLOPT_HTTPHEADER, array("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8","Accept-Language: pl,en-us;q=0.7,en;q=0.3", "Connection: keep-alive","Cache-Control: max-age=0","text/html; charset=UTF-8"));
curl_setopt($zapytanie, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($zapytanie, CURLOPT_COOKIEFILE, dirname(__file__) . '/cookies/'.$this->adres_ip.'/cookies.txt'); // ciacha
curl_setopt($zapytanie, CURLOPT_COOKIEJAR, dirname(__file__) . '/cookies/'.$this->adres_ip.'/cookies.txt'); // ciacha
$this->data = curl_exec($zapytanie);
$this->getinfo = curl_getinfo($zapytanie);
curl_close($zapytanie);
}
private function POSTrequest($link,$post){
$zapytanie = curl_init(); // adres strony
curl_setopt($zapytanie, CURLOPT_URL, $link);
curl_setopt($zapytanie, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.4) Gecko/20091030 Gentoo Firefox/3.5.4"); // useragent
curl_setopt($zapytanie, CURLOPT_HTTPHEADER, array("Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8","Accept-Language: pl,en-us;q=0.7,en;q=0.3","Referer: https://www.linkedin.com/uas/login-submit", "Connection: keep-alive","Content-Type: application/x-www-form-urlencoded"));
curl_setopt($zapytanie, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($zapytanie, CURLOPT_COOKIEFILE, dirname(__file__) . '/cookies/'.$this->adres_ip.'/cookies.txt'); // ciacha
curl_setopt($zapytanie, CURLOPT_COOKIEJAR, dirname(__file__) . '/cookies/'.$this->adres_ip.'/cookies.txt'); // ciacha
curl_setopt($zapytanie, CURLOPT_POST, 1);
curl_setopt($zapytanie, CURLOPT_POSTFIELDS, $post);
$this->data = curl_exec($zapytanie);
$this->getinfo = curl_getinfo($zapytanie);
curl_close($zapytanie);
}