Curl 无法卷曲远程文件
我有一段代码,可以接收任何URL并从web上删除它。到目前为止,它一直运行良好,直到有人给了它以下URL: 如果我在浏览器中点击它,它会显示得很好。但当我试着卷曲它时,我得到:Curl 无法卷曲远程文件,curl,Curl,我有一段代码,可以接收任何URL并从web上删除它。到目前为止,它一直运行良好,直到有人给了它以下URL: 如果我在浏览器中点击它,它会显示得很好。但当我试着卷曲它时,我得到: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>403 Forbidden</title> </head><body> <h1>F
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access /static/images/aspen_hill-rom_logo.png
on this server.</p>
<hr>
<address> Server at www.aspensurgical.com Port 80</address>
</body></html>
他们的服务器是否意识到我不是一个普通的浏览器并启动了我?他们让useragent检查你是谁。添加普通浏览器的useragent,您应该会很好
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; rv:19.0) Gecko/20100101 Firefox/19.0");
以下是中的工作示例。一些服务器为了阻止不必要的流量,只允许从浏览器下载。因此,为了复制这样的服务器,curl还有一个额外的选项--user-agent,它可以做到这一点 我在windows7电脑上使用curl,安装了gow 范例
curl --user-agent "Mozilla/4.0" http://www.example.com/archives/abc.txt --output pqr.txt
我也有同样的问题
修理
和accept.php
<?php
if(isset($_FILES['myfile']['tmp_name'])) {
$path = "myfiles/" . $_FILES['myfile']['name'];
move_uploaded_file($_FILES['myfile']['tmp_name'], $path);
}
?>
先生,你应该得到一块大饼干。非常感谢!你能解释一下useragent吗?chrome、safari和其他浏览器怎么样?为什么我们需要添加它们?@Naeem每个浏览器都会发送自己的用户代理字符串来标识自己。通用搜索引擎机器人在用户代理字符串中显示它们为哪个搜索引擎工作。这就是为什么一些网站会挖掘这个字符串来查看谁请求页面。即使设置了用户代理,当我尝试curl时,这对我来说也不起作用https://usa.visa.com/support/consumer/travel-support/exchange-rate-calculator.html/?fromCurr=USD&toCurr=EUR&fee=0&exchangedate=02/08/2018“
没有想到这是修复方法,谢谢!如果这对其他人有帮助的话:我在将服务器从Debian Wheezy升级到Jessie后遇到了这个错误,其中包括Apache 2.2到2.4的升级,以及php 5.4到5.6的升级。2018年是的,我知道,我知道。。。
<form action="gc.php" method="post" enctype="multipart/form-data">
<input type="file" name="f">
<input type="submit" value="Post">
</form>
<?php
if(isset($_FILES['f']['tmp_name'])) {
$ch = curl_init();
$cfile = new CURLFile($_FILES['f']['tmp_name'], $_FILES['f']['type'],
$_FILES['f']['name']);
$data = array("myfile" =>$cfile);
curl_setopt($ch, CURLOPT_URL, "http://your-url/accept.php");
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 15);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($ch);
if($response == true) {
echo "File posted";
} else {
echo "Error" . curl_error($ch);
}
}
?>
<?php
if(isset($_FILES['myfile']['tmp_name'])) {
$path = "myfiles/" . $_FILES['myfile']['name'];
move_uploaded_file($_FILES['myfile']['tmp_name'], $path);
}
?>