php - 无法在 PHP 中使用 cURL 发送

标签 php curl

我在 0fees.net 上创建了一个测试主机。我还创建了一个小的 PHP 脚本,它将接收我希望发送的文件。

我尝试了很多方法,但服务器响应 HTTP 403 Forbidden;详细输出中的实际消息是

* About to connect() to ********* port 80 (#0)
*   Trying 209.190.85.12... * connected
* Connected to ******* (209.190.85.12) port 80 (#0)
> POST /index.php HTTP/1.1
Host: *************
Accept: */*
Content-Length: 791
Expect: 100-continue
Content-Type: multipart/form-data; boundary=----------------------------4cad4df8
02c5

* The requested URL returned error: 403
* Closing connection #0
* HTTP response code said error

我使用的代码是

curl_easy_setopt(curl, CURLOPT_URL, link);
curl_easy_setopt(curl, CURLOPT_HEADER, "User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.30 Safari/534.30");
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
curl_easy_setopt(curl, CURLOPT_FAILONERROR, true);
curl_easy_setopt (curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt (curl, CURLOPT_POST, 1);
curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "");
curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
curl_easy_perform(curl);

我添加的大部分 curlopts 内容只是因为我收到上述 http 403 错误。我该如何解决这个问题?

附言 此代码在我的本地主机设置上完美运行!

最佳答案

403 forbidden 通常意味着您正在使用错误的方法或向错误的 URL 发送请求。

关于php - 无法在 PHP 中使用 cURL 发送,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5964633/

相关文章:

php - 使用 CSS 和 PHP 导航 - 基于图像的悬停菜单 (jQuery)

ssl - 隔离 Azure Kubernetes 服务 (AKS) SSL 错误

c++ - 为什么我的程序发送 'Anonymous IP Packets' 以及如何阻止它?

php - cURL 错误 35 - 连接到 api.rkd.reuters.com 时出现未知 SSL 协议(protocol)错误 :443

php - 如何删除wordpress静态主页中的页面名称?

php - 如何使用 PHP 从 XML 文件中获取特定子项并在 div 上显示其子项

linux - 变量不在 linux 中的 curl 命令中扩展

c++ - 使用 libcurl 库与使用 system() 调用 curl

php - 如何在 PHP 中跟踪用户位置/区域

javascript - ajax 会增加还是降低安全性?