2014-09-02 1 views
2

내 웹 사이트에서 PHP 컬을 사용하여 ASP 사이트에 데이터를 게시해야합니다.PHP 컬을 사용하여 ASP 사이트에 데이터를 게시하는 방법

ASP 사이트는 내가

  1. 쿠키를 & 세션과는

  2. 을 유지하기 위해 PHP 컬을 사용하여 해당 웹 사이트에서 웹 페이지의 HTML 소스를 크롤링 아래처럼 접근이 점에 대한 http://www.hotfrog.com.au/AddYourBusinessSingle.aspx

    입니다 소스 ASP 비공개 변수 값 추출

  3. 필요한 양식 필드가있는 준비된 포스트 문자열

  4. 그리고 PHP 컬을 사용하여 ASP 사이트 URL을 대상으로 데이터를 게시했지만 응답은 해당 페이지 양식 정보에 항목 정보가 없으며 해당 항목에도 비 입력 필드에 대한 컬 응답의 유효성 검사 메시지가 표시되지 않습니다. 이 프로세스

  5. 는 CURLOPT_USERAGENT, CURLOPT_COOKIEJAR, CURLOPT_COOKIEFILE 대해 동일한 값을 유지

    ctl00 $ contentSection $ CompanyDetailsControl $ txtBusinessName

    ctl00 $으로 아래 이런

ASP 사이트 요구 양식 필드 contentSection $ CompanyDetailsControl $ txt 서바이벌

게시 할 항목입니다. 직접 또는 거기에 어떤 필드가 필요한 PHP는 꼬리에 의해 대상 사이트에 게시하기 전에 인코딩 필요

아무도이 솔루션이나 PHP는 컬에 의해 ASP 사이트에 대한 다른 접근법에 대한 해결책을 가질 수 있습니까?

답변

1

사용

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("__YOUR__URL__HERE__"); 
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'  => '', 
    '__EVENTARGUMENT'  => '', 
    '__VIEWSTATE'   => $viewstate, 
    '__EVENTVALIDATION' => $eventval, 
    'ctl00%24txtUsername' => 'xxx', 
    'ctl00%24txtPassword' => 'xxx', 
    'ctl00$ImgLogin.x' => '0', 
    'ctl00$ImgLogin.y' => '0',]; 

$ch2 = curl_init("http://gsc.klub-modul.dk/cms/ShowContentPage.aspx?ContentPageID=1"); 
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 />"; 
    } 
} 
관련 문제