php - 如何在 PHP 中使用 file_get_contents() 请求移动版本?

标签 php curl user-agent

感谢您查看我的问题。

我想通过使用 file_get_contents() 或 cURL 获取移动版本。我知道这可以通过修改请求中的 HTTP header 来完成。你能给我一个简单的例子吗?

再次感谢!

问候, 桑凯特

最佳答案

作为替代方案,file_get_contentsstream_context_create也可以使用:

$opts = array('http' =>
    array(
        'header'  => 'User-agent: Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420.1 (KHTML, like Gecko) Version/3.0 Mobile/3B48b Safari/419.3',
    )
);

$context  = stream_context_create($opts);

$result = file_get_contents($url, false, $context);

关于php - 如何在 PHP 中使用 file_get_contents() 请求移动版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4936930/

相关文章:

php - 移动用户代理获取详细信息

php - 在数据库中组织类数据的最佳方式是什么?

php - 在页面上包含 API 的最有效方法是什么?

php - 我应该在每次请求时动态生成每个缩略图,还是将它们存储在图像上传时?

php - PayPal Rest SDK API - 获取 token

php - cURL 响应 header

php - 执行大sql语句时出错

json - 为什么我在此 cURL 调用中的请求正文中收到格式错误的 JSON?

browser - 什么是用户代理?

c# - 用户代理正则表达式