PHP cURL请求更改POST数据

时间:2014-04-13 23:45:24

标签: php post curl firebug

使用PHP cURL模块我的POST请求有问题。我有一个像这样的字符串$new_post(在这里裁剪,因为它太长了):

    $new_post = '...AvailabilitySearchInputScheduleSelectView$RadioButtonMarketStructure='.$tipe.'&AvailabilitySearchInputScheduleSelectView$DropDownListMarketDay1='.$tanggal1.'&AvailabilitySearchInputScheduleSelectView$DropDownListMarketMonth1='.$bulan1.'&date_picker='.$bulan1.'-'.$tanggal1.'&AvailabilitySearchInputScheduleSelectView$DropDownListMarketDay2='.$tanggal2.'&AvailabilitySearchInputScheduleSelectView$DropDownListMarketMonth2='.$bulan2.'&date_picker='.$bulan2.'-'.$tanggal2.'&...;

当我使用curl_exec发布时,POST字符串会自行更改。子串AvailabilitySearchInputScheduleSelectView变为AvailabilitySearchInputSearchView。我用Firebug检查了它。

我不知道为什么会这样。谁能告诉我为什么会这样?这是我的请求代码:

    $data = curl_init();
    curl_setopt($data, CURLOPT_CONNECTTIMEOUT, 180);
    curl_setopt($data, CURLOPT_URL, $url);
    curl_setopt($data, CURLOPT_FAILONERROR,1);
    curl_setopt($data, CURLOPT_FOLLOWLOCATION,1);
    curl_setopt($data, CURLOPT_VERBOSE, 1);
    curl_setopt($data, CURLOPT_POST, true);
    curl_setopt($data, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($data, CURLOPT_POSTFIELDS, $new_post);
    curl_setopt($data, CURLOPT_FAILONERROR,0);
    curl_setopt($data, CURLINFO_HEADER_OUT, true);
    curl_setopt($data, CURLOPT_COOKIEJAR, $cookie);
    curl_setopt($data, CURLOPT_COOKIEFILE, $cookie);
    curl_setopt($data, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0");
    $result = curl_exec($data);

*编辑

如果我在真实的网页上这是正确的帖子。我试图以同样的方式发布。对不起,我可以上传我的萤火虫的截图,因为我没有足够的声誉。

__ EVENTTARGET =安培; __ EVENTARGUMENT =安培; __ VIEWSTATE =%2FwEPDwUBMGRkBsrCYiDYbQKCOcoq%2FUTudEf14vk%3D&安培; pageToken =安培; AvailabilitySearchInputScheduleSelectVieworiginStation1 =安培; AvailabilitySearchInputScheduleSelectView%24TextBoxMarketOrigin1 =安培; AvailabilitySearchInputScheduleSelectViewdestinationStation1 =安培; AvailabilitySearchInputScheduleSelectView%24TextBoxMarketDestination1 =安培; AvailabilitySearchInputScheduleSelectVieworiginStation2 =安培; AvailabilitySearchInputScheduleSelectView% 24TextBoxMarketOrigin2 =安培; AvailabilitySearchInputScheduleSelectViewdestinationStation2 =安培; AvailabilitySearchInputScheduleSelectView%24TextBoxMarketDestination2 =安培; AvailabilitySearchInputScheduleSelectView%24RadioButtonMarketStructure =往返&安培; AvailabilitySearchInputScheduleSelectView%24DropDownListMarketDay1 = 14&安培; AvailabilitySearchInputScheduleSelectView%24DropDownListMarketMonth1 = 2014-04&安培; date_picker = 2014年4月14日&安培; AvailabilitySearchInputScheduleSelectView%24DropDownListMarketDay2 = 2 1安培; AvailabilitySearchInputScheduleSelectView%24DropDownListMarketMonth2 = 2014-04&安培; date_picker = 2014年4月21日&安培; AvailabilitySearchInputScheduleSelectView%24DropDownListPassengerType_ADT = 3及AvailabilitySearchInputScheduleSelectView%24DropDownListPassengerType_CHD = 0&安培; AvailabilitySearchInputScheduleSelectView%24DropDownListPassengerType_INFANT = 0&安培; AvailabilitySearchInputScheduleSelectView%24DropDownListSearchBy = columnView&安培; AvailabilitySearchInputScheduleSelectView%24DdlCurrencyDynamic = IDR&安培; ControlGroupScheduleSelectView% 24AvailabilityInputScheduleSelectView%24HiddenFieldTabIndex1 = 4和; ControlGroupScheduleSelectView%24AvailabilityInputScheduleSelectView%24market1 = 0%7EP%7E%7EP%7ERGFR%7E%7E1%7EX%7CQG%7E + 853%7E +%7E%7EDPS%7E04%2F22%2F2014 + 20%3A05% 7ECGK%7E04%2F22%2F2014 + 20%3A50%7E&安培; ControlGroupScheduleSelectView%24AvailabilityInputScheduleSelectView%24HiddenFieldTabIndex2 = 4和; ControlGroupScheduleSelectView%24AvailabilityInputScheduleSelectView%24market2 = 0%7EQ%7E%7EQ%7ERGFR %7E%7E1%7EX%7CQG%7E + 852%7E +%7E%7ECGK%7E04%2F23%2F2014 + 16%3A40%7EDPS%7E04%2F23%2F2014 + 19%3A30%7E&安培; ControlGroupScheduleSelectView%24ButtonSubmit = Lanjutkan

2 个答案:

答案 0 :(得分:0)

您可以在将http_build_query()传递给curl_setopt()之前使用$post = array('foo'=>'bar', 'baz'=>'boom', 'cow'=>'milk', 'php'=>'AvailabilitySearchInputScheduleSelectView$RadioButtonMarketStructure'); $post = http_build_query($post); $data = curl_init(); curl_setopt($data, CURLOPT_CONNECTTIMEOUT, 180); curl_setopt($data, CURLOPT_URL, $url); curl_setopt($data, CURLOPT_FAILONERROR,1); curl_setopt($data, CURLOPT_FOLLOWLOCATION,1); curl_setopt($data, CURLOPT_VERBOSE, 1); curl_setopt($data, CURLOPT_POST, true); curl_setopt($data, CURLOPT_RETURNTRANSFER, true); curl_setopt($data, CURLOPT_POSTFIELDS, $post ); curl_setopt($data, CURLOPT_FAILONERROR,0); curl_setopt($data, CURLINFO_HEADER_OUT, true); curl_setopt($data, CURLOPT_COOKIEJAR, $cookie); curl_setopt($data, CURLOPT_COOKIEFILE, $cookie); curl_setopt($data, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0"); $result = curl_exec($data); ,如下所示:

{{1}}

答案 1 :(得分:0)

您不会在Firebug中看到cURL请求,因为它发生在服务器上。

  

当我的localhost将POST数据发送到URL(localhost / test2.php)时,我看到AvailabilitySearchInputSearchView,并且我也用firebug检查它。

如果您在Firebug中看到AvailabilitySearchInputSearchView但是在echo内通过curl_exec()调用的PHP脚本中获取了正确的POST正文,那么您的问题与cURL请求无关。