您知道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. 的doGet调用doPost方法或相反
- 4. 如何使这种方法的相反
- 5. Python中的相等或相等的方法正好相反
- 6. 词法相反
- 7. file_get_content无法加载的网站
- 8. 与SVGs PHP file_get_content
- 9. File_get_content错误
- 10. Porter Stemmer算法的“相反”?
- 11. System.Device.Location.GeoCoordinate.GetDistanceTo()的反方法
- 12. php file_get_content returing 401 on
- 13. file_get_content(转换为htmlspecialchars)
- 14. 下载file_get_content响应
- 15. 用cURL替换file_get_content()?
- 16. file_get_content的正则表达式
- 17. 是否有与LINQ的所有方法相反的东西?
- 18. Ruby中的Time.now.advance()的相反方向
- 19. SQL语法 - 相反选择
- 20. 如何在Ruby/Rails中清晰地定义“反义”或“相反”的方法?
- 21. 有效的方法来反转大相关矩阵
- 22. 以相反顺序打印链表的递归方法
- 23. 将DateTime转换为long值,也是相反的方法
- 24. 在Ruby中有没有与find相反的方法?
- 25. 与Ruby的CGI.parse方法完全相反吗?
- 26. PHP:需要一个timezone_name_from_abbr的相反方法吗?
- 27. 是否有`unittest.TestCase.fail()`通过Python单元测试的相反方法?
- 28. Java中创建一个相反的方法(公式问)
- 29. DelayQueue有没有相反的地方?
- 30. For循环在相反的方向
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