0

我正在尝试使用 curl 向服务器发送图像和更多选项,但我不知道为什么它不起作用。这是代码:

<?php

header('Location: https://www.reporo.com/analytics/inventory-advertiser-banner.php?clientid=xxxx&campaignid=xxxx&type=smrc');

$uploadUrl = "C:\wamp\www\autofill\demo_300x250.png";
$uploadUrl = "@$uploadUrl";


$post_data['description'] = 'Name';
$post_data['url'] = 'http://www.url.pl';
$post_data['campaignid'] = xxxxx;
$post_data['clientid'] = xxxxx;
$post_data['bannertext'] = 'some text';
$post_data['upload_smrc'] = $uploadUrl;

    foreach ( $post_data as $key => $value)
{
    $post_items[] = urlencode($key) . '=' . urlencode($value);
}
$post_string = implode ('&', $post_items);

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $post_string);
curl_setopt ($ch, CURLOPT_REFERER, "https://www.reporo.com/analytics/inventory-advertiser-banner.php?clientid=xxxxx&campaignid=xxxxx&type=smrc");
curl_setopt ($ch, CURLOPT_URL, 'https://www.reporo.com/analytics/inventory-advertiser-banner-update.php');
$upload_result = curl_exec ($ch);

curl_close ($ch);

?>

$post_data 中的索引是正确的。该表单与 CURLOPT_REFERER 位于同一链接中。我形成的字段操作包含:inventory-advertiser-banner-update.php。

此外,我无法使用 curl 登录到该站点,但是当我之前登录时,重定向可以正常工作,因此它应该可以正常工作。

有没有可能这个站点站点不能使用 curl ?我问是因为在我遇到登录问题之前我没有解决,现在这个问题。

也许有一种解决方法?

问候。

4

3 回答 3

1

关闭 SSL 对等验证不是一个好主意。如果您想使用 SSL 对等验证,您可以在 Windows 上为所有应用程序全局使用下一个解决方案:

  1. 从这里下载带有根证书的文件:http: //curl.haxx.se/docs/caextract.html
  2. 添加到 php.ini:

curl.cainfo=C:/path/to/ca-bundle.crt

这很神奇,CURL 现在可以验证证书。

于 2012-11-26T12:32:11.737 回答
0

这可能不是原因,但urlencode如果您手动构建 POST 字符串,则需要 POST 键和值。

foreach ($post_data as $key => $value) {
    $post_items[] = urlencode($key) . '=' . urlencode($value);
}
$post_string = implode ('&', $post_items);

否则,如果您的任何键或值包含等&,您将得到各种意外结果。=

话虽如此,您可以直接使用数组CURLOPT_POSTFIELDS

curl_setopt ($ch, CURLOPT_POSTFIELDS, $post_data);

于 2012-09-13T12:41:45.423 回答
-1

你可能有问题CURLOPT_SSL_VERIFYHOST

尝试

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
于 2012-09-13T12:39:37.117 回答