cURL 响应为 200,但它并没有真正发布值


cURL response is 200, but it doesn't really post the values

>我有以下使用 PHP 的 cURL 代码;

$product_id_edit="Playful Minds (1062)";
$item_description_edit="TEST";
$rank_edit="0";
$price_type_edit="2";
$price_value_edit="473";
$price_previous_value_edit="473";
$active_edit="1";
$platform_edit="ios";
//set POST variables
$url = 'https://www.domain.com/adm_test/phpgen/offline_items.php?operation=insert';
$useragent = 'Mozilla/5.0 (Windows NT 6.1; rv:8.0.1) Gecko/20100101 Firefox/8.0.1';
$fields = array(
   'product_id_edit'=>urlencode($product_id_edit),
   'item_description_edit'=>urlencode($item_description_edit),
   'rank_edit'=>urlencode($rank_edit),
   'price_type_edit'=>urlencode($price_type_edit),
   'price_value_edit'=>urlencode($price_value_edit),
   'price_previous_value_edit'=>urlencode($price_previous_value_edit),
   'active_edit'=>urlencode($active_edit),
   'platform_edit'=>urlencode($platform_edit)
);
$fields_string="";
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
//add useragent
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
curl_setopt($ch,CURLOPT_POST,count($fields));
//execute post
$result = curl_exec($ch);
if(curl_errno($ch)){
print "" . curl_error($ch);
}else{
//print_r($result);
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
//echo "HTTP Response Code: " . curl_error($ch);
echo $httpCode;
//close connection
curl_close($ch);

我已经打印$httpCode;我得到代码 200;我认为这没关系,因为我已经在手册页中阅读过,但是,当我检查站点时,POST 值不存在,

这是否与跨域有关,因为我没有在同一域上发布它?,我在 127.0.0.1/site/scrpt 上这样做.php但是如果不成功,我如何获得响应代码 200?

我还试图通过删除请求 URL 上的部分来获取 404,它确实返回了 404(这意味着 cURL 在我的假设中工作正常(

将 url 与"?operation=insert"https://www.domain.com/adm_test/phpgen/offline_items.php?operation=insert 有关系吗?

让我们假设(没有暗示(,我来自另一个网站,我希望将值发布为另一个网站的形式,就像一个机器人。 我的目标并不意味着任何邪恶的意图,如果这不可行,我必须编码数千行信息。

同样,我不需要服务器的响应(但如果有一个可用,那就好了(

操作应随CURLOPT_POSTFIELDS一起传递。以及其他参数。

在浏览器的情况下会发生跨域问题。而且您的代码似乎是 php 服务器端代码,所以这应该不是问题。

不确定这是解决方案还是问题不同,但是这一行:

rtrim($fields_string,'&');

应该是这样的:

$fields_string = rtrim($fields_string,'&');
curl_setopt($ch,CURLOPT_POST,TRUE);

CURLOPT_POST - 布尔值,它不是值的计数,而是使用帖子标志。

代码 200 表示连接设置正确并收到来自服务器的响应,但这并不意味着已实现请求的操作。

请求后打印$result以查看来自 Web 服务器的响应。