php ssl curl:对象移动错误 [英] php ssl curl : object moved error

查看:510
本文介绍了php ssl curl:对象移动错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个php脚本来抓取这个网站,并将数据发送给我。它似乎正确登录,因为当脚本运行时,它似乎重定向并给我一个消息,对象移动这里,这里是链接到default.aspx页面,这是什么发生当我手动登录。

Im developing a php script to scrape this website and email me the data to me. It seems to be logging in correctly because when the script runs, it seems to redirect and give me a message saying Object moved Here and the here is linked to the default.aspx page which is what exactly happens when I manually login.

以下是我的脚本:

<?php
$useragent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1";

// INIT CURL
$ch = curl_init();

//init curl 
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);

// SET URL FOR THE POST FORM LOGIN
curl_setopt($ch, CURLOPT_URL, 'https://access.manager.com/Login.aspx');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);

// Set your login and password for authentication
curl_setopt($ch, CURLOPT_USERPWD, 'testu:passwd');
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);


// This is occassionally required to stop CURL from verifying the peer's certificate.
// CURLOPT_SSL_VERIFYHOST may also need to be TRUE or FALSE if
// CURLOPT_SSL_VERIFYPEER is disabled (it defaults to 2 - check the existence of a
// common name and also verify that it matches the hostname provided)
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

// Optional: Return the result instead of printing it
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

// ENABLE HTTP POST
curl_setopt ($ch, CURLOPT_POST, 1);

// SET POST PARAMETERS : FORM VALUES FOR EACH FIELD
curl_setopt ($ch, CURLOPT_POSTFIELDS, 'Username=testu&Password=passwd');

# Setting CURLOPT_RETURNTRANSFER variable to 1 will force cURL
# not to print out the results of its query.
# Instead, it will return the results as a string return value
# from curl_exec() instead of the usual true/false.
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

// EXECUTE 1st REQUEST (FORM LOGIN)
$store = curl_exec ($ch);
echo $store;
// CLOSE CURL
curl_close ($ch);

?>

任何想法可能会阻止页面正确输出页面?我猜它没有正确的重定向。

any ideas what could be preventing the page to output the page correctly? I'm guessing its not redirecting correctly.

提前感谢

推荐答案

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);

更改为1.此外,在CURLOPT_SSL_VERIFYPEER后设置:

Change that to 1. Also, set this after CURLOPT_SSL_VERIFYPEER:

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

这篇关于php ssl curl:对象移动错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆