我在 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/