cURL 不返回任何内容? [英] cURL not returning anything?

查看:120
本文介绍了cURL 不返回任何内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<?php
error_reporting(-1);
$config = array
(
    "siteURL"        => "http://domain.com",
    "loginCheck"     => "checkuser.php",
    "userAgent"      => "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16"
);

$postFields = "username=user&password=pass&submit= Login ";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $config['siteURL'] . $config['loginCheck']);
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_USERAGENT, config['userAgent']);
curl_setopt($ch, CURLOPT_REFERER, config['siteURL']);

$content = curl_exec($ch);
curl_close($ch);

echo $content;

?>

我希望这与 curl 的结果相呼应,但事实并非如此.我做错了什么吗?

I expect this to be echoing the result of the curl, but its not. am I doing anything wrong?

推荐答案

它确实如此,如果你设置一个以/"结尾的完整 URL(修正另外两个错别字):

It does, if you set a complete URL with a '/' at the end (fix two other typos):

error_reporting(-1);
$config = array
(
    "siteURL"        => "http://www.apple.com/",
    "loginCheck"     => "checkuser.php",
    "userAgent"      => "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16"
);

$postFields = "username=user&password=pass&submit= Login ";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $config['siteURL'] . $config['loginCheck']);
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $config['userAgent']);
curl_setopt($ch, CURLOPT_REFERER, $config['siteURL']);

$content = curl_exec($ch);
curl_close($ch);

echo $content;

这篇关于cURL 不返回任何内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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