2016-09-17 17 views
0

我想从行星赢得优惠券数据我有视图,但不是优惠券数据。我使用所有asp窗体的参数,但是我不能提供优惠券数据。我认为,我在表单数据有问题或者与网络服务网站工作XHR rquest的请求头是用PHP提交aspx表单我有视图但不是数据

POST /Sport/default.aspx HTTP/1.1主机:ww3.365planetwinall.net 连接: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,像Gecko)Chrome/52.0.2743.116 Safari/537.36 Content-Type: application/x-www-form-urlencoded;字符集= UTF-8接受:/的Referer: https://ww3.365planetwinall.net/Sport/default.aspx接受编码: gzip的,放气,BR的Accept-Language: FR-FR,FR; Q = 0.8,的en-US; Q = 0.6,连接; 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 =(引荐)| utmcmd =转诊| 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); 
?> 

回答

0
function get_headers_from_curl_response($headerContent) { 

    $headers = []; 

    // Split the string on every "double" new line. 
    $arrRequests = explode("\r\n\r\n", $headerContent); 

    // Loop of response headers. The "count() -1" is to 
    //avoid an empty row for the extra line break before the body of the esponse. 
    for ($index = 0; $index < count($arrRequests) - 1; $index++) { 

     foreach (explode("\r\n", $arrRequests[$index]) as $i => $line) { 
      if ($i === 0) { 
       $headers[$index]['http_code'] = $line; 
      } 
      else { 
       list ($key, $value) = explode(': ', $line); 
       $headers[$index][$key] = $value; 
      } 
     } 
    } 

    return $headers; 
} 

function regexExtract($text, $regex, $regs, $nthValue) { 
    if (preg_match($regex, $text, $regs)) { 
     $result = $regs[$nthValue]; 
    } 
    else { 
     $result = ""; 
    } 

    return $result; 
} 

$regexViewstate = '/__VIEWSTATE\" value=\"(.*)\"/i'; 
$regexEventVal = '/__EVENTVALIDATION\" value=\"(.*)\"/i'; 

$ch = curl_init("https://m3.365planetwinall.net/Schedina.aspx"); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_HEADER, 1); 
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookies.txt'); 

$response = curl_exec($ch); 
curl_close($ch); 

$viewstate = regexExtract($response, $regexViewstate, $regs, 1); 
$eventval = regexExtract($response, $regexEventVal, $regs, 1); 

$params = [ 
'__EVENTTARGET'=>'ctl00$w$ContentMain$ContentMain$Coupon1$lnkCaricaCouponCodiceAnonimo', 
'__VIEWSTATEGENERATOR'=>'748FF232', 
    '__EVENTARGUMENT'  => '', 
    '__VIEWSTATE'   => $viewstate, 
    '__EVENTVALIDATION' => $eventval, 
    'ctl00$w$SM'=>'ctl00$w$ContentMain$ContentMain$Coupon1$atlasCoupon|ctl00$w$ContentMain$ContentMain$Coupon1$lnkCaricaCouponCodiceAnonimo', 
'ctl00$w$ContentMain$ContentMain$Coupon1$hidRiserva'=>'0', 
'ctl00$w$ContentMain$ContentMain$Coupon1$hidAttesa'=>'0', 
'ctl00$w$ContentMain$ContentMain$Coupon1$hidTipoCoupon'=>'', 
'ctl00$w$ContentMain$ContentMain$Coupon1$hidStatoCoupon'=>'0', 
'ctl00$w$ContentMain$ContentMain$Coupon1$hidBonusNumScommesse'=>'', 
'ctl00$w$ContentMain$ContentMain$Coupon1$hidQuotaTotaleDIMax'=>'', 
'ctl00$w$ContentMain$ContentMain$Coupon1$hidQuotaTotaleDIMin'=>'', 
'ctl00$w$ContentMain$ContentMain$Coupon1$hidQuotaTotale'=>'', 
'ctl00$w$ContentMain$ContentMain$Coupon1$hidIDQuote'=>'', 
'ctl00$w$ContentMain$ContentMain$Coupon1$hidModificatoQuote'=>'1', 
'ctl00$w$ContentMain$ContentMain$Coupon1$hidBonusQuotaMinimaAttivo'=>'0', 
'ctl00$w$ContentMain$ContentMain$Coupon1$hidBonusRaggruppamentoMinimo'=>'0', 
'ctl00$w$ContentMain$ContentMain$Coupon1$hidNumItemCoupon'=>'', 
'ctl00$w$ContentMain$ContentMain$Coupon1$hidIDCoupon'=>'', 
'ctl00$w$ContentMain$ContentMain$Coupon1$hidPrintAsincronoDisabled'=>'0', 
'ctl00$w$ContentMain$ContentMain$Coupon1$txtCouponCodiceAnonimo'=>$code_coupon, 
'ctl00$w$ContentMain$ContentMain$Coupon1$txtIDQuota'=>'', 
'ctl00$w$ContentMain$ContentMain$Coupon1$txtQB'=>'', 
'ctl00$w$ContentMain$ContentMain$Coupon1$txtAddImporto'=>'', 
'ctl00$w$ContentMain$ContentMain$Coupon1$txtIDCouponPrecompilato'=>'', 
'ctl00$w$ContentMain$ContentMain$Coupon1$txtImportoCouponPrecompilato'=>'', 
'__ASYNCPOST'=>'false' 
    ]; 

$ch2 = curl_init("https://m3.365planetwinall.net/Schedina.aspx"); 
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch2, CURLOPT_HEADER, 1); 
curl_setopt($ch2, CURLOPT_POST, true); 
curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch2, CURLOPT_POSTFIELDS, http_build_query($params)); 
curl_setopt($ch2, CURLOPT_COOKIE, 'cookies.txt'); 
curl_setopt($ch2, CURLOPT_COOKIEJAR, 'cookies2.txt'); 

$response2 = curl_exec($ch2); 
curl_close($ch2); 

foreach (get_headers_from_curl_response($response2) as $value) { 
    foreach ($value as $key => $value2) { 
     // echo $key.": ".$value2."<br />"; 
    } 
} 
0

如果你的问题是根本不会让我感到吃惊, 您发送使用multipart/form-data, 很多服务器不正确地分析了POST请求,代替 将会预期为application/x-www-form-urlencoded。 来解决这个问题,与其他 curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postfields));

笔记代替curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); 根本就 curl_setopt($ch,CURLOPT_POST,true); 代替。

你的UA字符串包含换行符。很确定这不是你想要的,我不知道任何实际上在用户代理头部有换行符的浏览器。

便携性的缘故,用的fopen把wb

它可能会更好地使用DOM文档解析您的HTML。

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

(很多专家对正则表达式同意不适合用于解析HTML。看RegEx match open tags except XHTML self-contained tags例如)

设置CURLOPT_ENCODING空字符串将神奇地让你的传输速度更快。

,如果你不需要饼干剧本完成后,你应该在脚本执行,年底做

$ckfileh=tmpfile(); $ckfile=stream_get_meta_data($ckfileh)['uri'];而不是使用tmpnam(),因为它会自动清除TMPFILES()wheras您tmpnam()方法会在/ tmp中留下垃圾,除非您在脚本完成时手动显式删除它。

+0

可以修复我的代码我不是专家在卷曲 – zratan