2012-07-04 35 views
0

如何將GET/POST數據發送到需要使用file_get_contents進行授權的服務器?file_get_contents - 授權和發送數據

我知道如何發送GET/POST數據並在file_get_contents中授權,但不知道將這些數據合併到一起。 有人可以幫忙嗎?

+0

測試通過把這樣的登錄信息http:// username:[email protected]/file.txt – NoLifeKing

回答

0

是的,這是可能的,類似的東西與從協議(重新)設置選項的情況下使用:

function http_post($url, $data) { 
$serialized_data = http_build_query($data); 
$options = array(
    'http' => array(
     'method' => 'POST', 
     'header' => "Content-type: application/x-www-form-urlencoded\r\n" . 'Content-Length: ' . strlen($serialized_data) . "\r\n", 
     'content' => $serialized_data 
    ) 
); 
$contexte = stream_context_create($options); 
return file_get_contents($url, 0, $contexte); 

}

$內容= HTTP_POST(的「http://域名/ mypage',array('var1'=>'val1',/ * ... * /,'varN'=>'valN'));

你想要更多的解釋?

+0

謝謝,它解決了我的問題 – user1410263