2012-06-25 4 views
-5

질문이 있습니다. 먼저 사이트에 데이터를 게시 한 다음 데이터를 게시 한 사이트의 소스 코드를 가져올 수 있습니까?데이터 게시 및 소스 코드 표시

은 이걸로 시도 :

$html = file_get_contents('http://test.com/test.php?test=test'); 

그러나 테스트 = 테스트는 $ _GET ....

그래서 그래, 나는 누군가가 나를 도울 수 있기를 바랍니다있다?! :)
미리 감사드립니다 (나쁜 영어로 죄송합니다!).

+0

시도 컬 포스트 http://davidwalsh.name/execute-http-post-php-curl –

+0

당신은 곱슬 곱슬에 대한 소스 코드가 아닌 요청에 의해 생성 된 HTML을 얻을 수 있습니다. –

답변

1

:에서

// Create map with request parameters 
$params = array ('surname' => 'Filip', 'lastname' => 'Czaja'); 

// Build Http query using params 
$query = http_build_query ($params); 

// Create Http context details 
$contextData = array ( 
       'method' => 'POST', 
       'header' => "Connection: close\r\n". 
          "Content-Length: ".strlen($query)."\r\n", 
       'content'=> $query); 

// Create context resource for our request 
$context = stream_context_create (array ('http' => $contextData)); 

// Read page rendered as result of your POST request 
$result = file_get_contents (
        'http://www.sample-post-page.com', // page url 
        false, 
        $context); 

// Server response is now stored in $result variable so you can process it 

상황

$postdata = http_build_query(
    array(
     'var1' => 'some content', 
     'var2' => 'doh' 
    ) 
); 

$opts = array(
    'http' => array(
     'method' => "POST", 
     'header' => "Connection: close\r\n". 
         "Content-Length: ".strlen($postdata)."\r\n", 
     'content' => $postdata 
) 
); 

$context = stream_context_create($opts); 

$result = file_get_contents('http://example.com/submit.php', false, $context); 
- 작은 버그가 있어야한다

// 편집 :

$opts = array(
    'http' => array(
     'method' => "POST", 
     'header' => "Connection: close\r\n". 
        "Content-type: application/x-www-form-urlencoded\r\n". 
        "Content-Length: ".strlen($postdata)."\r\n", 
     'content' => $postdata 
) 
); 
+0

테스트 할 때 http://example.com/submit.php로 "리디렉션"됩니까? – GuiceU

+0

당신은 URL을 입력해야합니다. 이것은 단지 예입니다 ... –

+0

물론 제가 그 일을합니다 ... – GuiceU

0

원본을 가져올 수는 없지만 서버에서 제공 한대로 페이지/출력을 가져올 수 있습니다. file_get_contents()을 언급하면서 POST 요청을 보내기 위해 사용할 수 있지만 다음과 같이 보일 것입니다. 이 기능의 3 매개 변수를 사용할 수 있습니다 http://fczaja.blogspot.se/2011/07/php-how-to-send-post-request-with.html

관련 문제