您知道PHP中有一個名爲file_get_content的方法,它可以獲取所提供url的頁面內容嗎?有沒有相反的方法呢?比如,file_post_content,您可以在其中將數據發佈到外部網站?只是要求教育目的。file_get_content的相反方法
0
A
回答
1
您可以使用不捲曲,但file_get_contents
PHP這個例子:
$url = 'URL';
$data = array('field1' => 'value', 'field2' => 'value');
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data),
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
var_dump($result);
查看PHP網站:http://php.net/manual/en/function.file-get-contents.php#102575
0
能寫一個:
<?php
function file_post_content($url, $data = array()){
// Collect URL. Optional Array of DATA ['name' => 'value']
// Return response from server or FALSE
if(empty($url)){
return false;
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
if(count($data)){
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
}
// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$svr_out = curl_exec ($ch);
curl_close ($ch);
return $svr_out;
}
?>
相關問題
- 1. BitConverter.ToString的相反方法?
- 2. 如何使這種方法的相反
- 3. 相反的提取方法重構
- 4. 詞法相反
- 5. file_get_content無法加載的網站
- 6. File_get_content錯誤
- 7. Ip日誌file_get_content()
- 8. 與SVGs PHP file_get_content
- 9. Porter Stemmer算法的「相反」?
- 10. System.Device.Location.GeoCoordinate.GetDistanceTo()的反方法
- 11. 用cURL替換file_get_content()?
- 12. 反轉方法?
- 13. Ruby中的Time.now.advance()的相反方向
- 14. 與Ruby的CGI.parse方法完全相反嗎?
- 15. Java中創建一個相反的方法(公式問)
- 16. PHP:需要一個timezone_name_from_abbr的相反方法嗎?
- 17. 將DateTime轉換爲long值,也是相反的方法
- 18. 在Ruby中有沒有與find相反的方法?
- 19. 是否有`unittest.TestCase.fail()`通過Python單元測試的相反方法?
- 20. 相反方向的角度標籤?
- 21. DelayQueue有沒有相反的地方?
- 22. C#反思方法?
- 23. 更換捲曲與file_get_content
- 24. 從file_get_content獲取特定值
- 25. 如何從功能file_get_content()
- 26. 與file_get_content獲取數據
- 27. file_get_content和變量問題
- 28. ShouldBeEquivalentTo的相反
- 29. 相反SUBSTR的
- 30. 兩個相同的記錄不反應相同的方式
PHP的的file_get_contents功能從本地讀取數據/遠程文件。還有一個名爲file_put_contents(http://php.net/file_put_contents)的函數來在本地寫文件。遠程編寫文件是另一回事。 –
請參閱本問答關於使用'curl'發佈數據http://stackoverflow.com/questions/2138527/php-curl-http-post-sample-code –
我也會迴應cURL。你也可以編寫一個這樣做的函數。 – Twisty