dongmao3148 2016-09-17 02:11
浏览 50
已采纳

用Php提交aspx表单我有视图但没有数据

I want to have the coupon data from planet win I have the view, but not the coupon data. I use all the params of asp forms but I can't have the coupon data please help. I think that I have a problem in the form data or the site work with web service the request header of the xhr rquest is

POST /Sport/default.aspx HTTP/1.1 Host: ww3.365planetwinall.net Connection: keep-alive Content-Length: 10353 Cache-Control: no-cache Origin: https://ww3.365planetwinall.net X-MicrosoftAjax: Delta=true User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36 Content-Type: application/x-www-form-urlencoded; charset=UTF-8 Accept: / Referer: https://ww3.365planetwinall.net/Sport/default.aspx Accept-Encoding: gzip, deflate, br Accept-Language: fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4,ar;q=0.2 Cookie: Comm100_CC_Identity_178373=-28931327; ISBets_CurrentOddsFormat=1; ISBets_CurrentGMT=41; ASP.NET_SessionId=i2avbkrxv4pvls55sw4d1j45; __utmt=1; __utma=1.1764843245.1455596018.1473978904.1474078088.172; __utmb=1.2.10.1474078088; __utmc=1; __utmz=1.1473331905.170.21.utmcsr=zalozi.com|utmccn=(referral)|utmcmd=referral|utmcct=/planetwin365; comm100_session_178373=-35985514; comm100_guid2_178373=5d22b4d2847a4e0d82cc3db3afeb5177; ISBets_CurrentCulture=11; _ga=GA1.2.1764843245.1455596018; _dc_gtm_UA-63917352-3=1; _ga=GA1.3.1764843245.1455596018; _dc_gtm_UA-63917352-10=1

 <?php

$url = "https://ww3.365planetwinall.net/Sport/default.aspx";
$ckfile = tempnam("/tmp", "CURLCOOKIE");
$useragent = 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US)  

AppleWebKit/533.2 (KHTML, like Gecko) Chrome/5.0.342.3 Safari/533.2';

//$username = "XXXXXXXXXX";
//$password = "XXXXXXXXXX";


$f = fopen('log.txt', 'w'); // file to write request header for debug  

  purpose

/**
    Get __VIEWSTATE & __EVENTVALIDATION
 */
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);

$html = curl_exec($ch);

curl_close($ch);

preg_match('~<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="(.*?)" />~', $html, $viewstate);
preg_match('~<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="(.*?)" />~', $html, $eventValidation);

$viewstate = $viewstate[1];
$eventValidation = $eventValidation[1];



/**
 Start Login process
 */
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile);
curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_STDERR, $f);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);

// Collecting all POST fields
$postfields = array();

$postfields['h$w$SM'] = 'h$w$PC$cCoupon$atlasCoupon|h$w$PC$cCoupon$lnkCaricaCouponCodiceAnonimo';
$postfields['h$w$cLogin$ctrlLogin$Username'] = "";
$postfields['h$w$cLogin$ctrlLogin$Password'] = '';
$postfields['h$w$PC$oddsSearch$txtSearch'] = '';
$postfields['h$w$PC$cSport$hidSportTime'] = '';
$postfields['h$w$PC$ctl02$txtVincita'] = "100";
$postfields['h$w$PC$ctl02$txtGiocata'] = "1";
$postfields['h$w$PC$CouponCheck1$txtCodiceCoupon'] = '';
$postfields['h$w$PC$ctl12$hidQuoteCoupon'] =              

 '4177834906§4189204249§4192948716§4191682218§4192727992§';
$postfields['h$w$PC$cCoupon$hidRiserva'] = "0";
$postfields['h$w$PC$cCoupon$hidAttesa'] = "0";
$postfields['h$w$PC$cCoupon$hidCouponAsincrono'] = "0";
$postfields['h$w$PC$cCoupon$hidIsTemporaryCoupon'] = '';
$postfields['h$w$PC$cCoupon$hidTipoCoupon'] = "4";
$postfields['h$w$PC$cCoupon$hidStatoCoupon'] = "0";
$postfields['h$w$PC$cCoupon$hidBonusNumScommesse'] = "1.1000";
$postfields['h$w$PC$cCoupon$hidQuotaTotaleDIMax'] = '';
$postfields['h$w$PC$cCoupon$hidQuotaTotaleDIMin'] = '';
$postfields['h$w$PC$cCoupon$hidQuotaTotale'] = '112,66';
$postfields['h$w$PC$cCoupon$hidIDQuote'] = '';
$postfields['h$w$PC$cCoupon$hidModificatoQuote'] = "1";
$postfields['h$w$PC$cCoupon$hidBonusQuotaMinimaAttivo'] = "0";
$postfields['h$w$PC$cCoupon$hidBonusRaggruppamentoMinimo'] = '0';
$postfields['h$w$PC$cCoupon$hidNumItemCoupon'] = '0';
$postfields['h$w$PC$cCoupon$hidPrintAsincronoDisabled'] = '0';
$postfields['h$w$PC$cCoupon$txtCouponCodiceAnonimo'] = 'TD426';
$postfields['h$w$PC$cCoupon$txtIDQuota'] = '';
$postfields['h$w$PC$cCoupon$txtSottoEventName'] = '';
$postfields['h$w$PC$cCoupon$txtQuota'] = '';
$postfields['h$w$PC$cCoupon$txtCodPubblicazione'] = '';
$postfields['h$w$PC$cCoupon$txtIDEvento'] = '';
$postfields['h$w$PC$cCoupon$txtEventName'] = '';
$postfields['h$w$PC$cCoupon$txtIDSottoEvento'] = '';
$postfields['h$w$PC$cCoupon$txtGiocabilita'] = '';
$postfields['h$w$PC$cCoupon$txtTipoQuota'] = '';
$postfields['h$w$PC$cCoupon$txtIDTipoEvento'] = '';
$postfields['h$w$PC$cCoupon$txtIDTipoQuota'] = '';
$postfields['h$w$PC$cCoupon$txtQB'] = '';
$postfields['h$w$PC$cCoupon$txtAddImporto'] = '';
$postfields['h$w$PC$cCoupon$txtIDCouponPrecompilato'] = '';
$postfields['h$w$PC$cCoupon$txtImportoCouponPrecompilato'] = '';
$postfields['__EVENTTARGET'] = "h$w$PC$cCoupon$btnFakeLoad";
$postfields['__EVENTARGUMENT'] = "";
$postfields['__ASYNCPOST'] = "true";
$postfields['__VIEWSTATEGENERATOR'] = "15C4A0A3";
$postfields['__VIEWSTATE'] = $viewstate;
$postfields['__EVENTVALIDATION'] = $eventValidation;

curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
$ret = curl_exec($ch); // Get result after login page.

var_dump($ret) ;
echo 'Erreur Curl : ' . curl_error($ch);
?>
  • 写回答

2条回答 默认 最新

  • douguan8940 2016-09-17 08:31
    关注

    it wouldn't surprise me if your problem is simply, you send the POST request using multipart/form-data, a lot of servers don't parse that correctly, and would expect application/x-www-form-urlencoded instead. to fix that, replace curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); with curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postfields));

    other notes:

    do not curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); simply do curl_setopt($ch,CURLOPT_POST,true); instead.

    your UA string contains newlines. pretty sure that's not what you want, i don't know any browser that actually has a newline in the user-agent header.

    for the sake of portability, fopen with 'wb'

    it would probably be better to use DOMDocument to parse your html.

    $viewstate=(@DOMDocument::loadHTML($html))->getElementById('__VIEWSTATE')->getAttribute("value"); $eventValidation=(@DOMDocument::loadHTML($html))->getElementById('__EVENTVALIDATION')->getAttribute("value");

    (a lot of experts agree on that regular expressions are not fit for parsing html. see RegEx match open tags except XHTML self-contained tags for example)

    setting CURLOPT_ENCODING to empty string would magically make your transfers faster.

    if you don't need the cookies after the script has finished, you should probably do

    $ckfileh=tmpfile(); $ckfile=stream_get_meta_data($ckfileh)['uri']; instead of tmpnam() as it will automatically clear the tmpfiles() at the end of script execution, wheras your tmpnam() approach leaves junk in /tmp unless you manually explicitly delete it on script completion.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)