php采用file_get_contents代替使用curl实例,curlgetcontents
php采用file_get_contents代替使用curl实例,curlgetcontents
本文实例讲述了php采用file_get_contents代替使用curl的方法,分享给大家供大家参考。具体实现方法如下:
file_get_contents代替使用curl其实不多见了,但有时你碰到服务器不支持curl时我们可以使用file_get_contents代替使用curl,下面看个例子。
当用尽一切办法发现 服务器真的无法使用curl时。或者curl不支持https时。curl https 出现502时。你又不想重装网站环境的时候,你就改用file_get_contents 代替吧。
curl 经常使用的 curl get curl post
curl get 替代 直接用file_get_contents($url) 就可以了
curl post 替代如下:
复制代码 代码如下:
function Post($url, $post = null) {
$content = http_build_query($post);
$content_length = strlen($content);
$options = array(
'http' => array(
'method' => 'POST',
'header' =>"Content-type: application/x-www-form-urlencoded",
'content' => $post
)
);
return file_get_contents($url, false, stream_context_create($options));
}
希望本文所述对大家的php程序设计有所帮助。
模拟个头部信息
array( 'method'=>"GET", 'header'=>"User-Agent: ".$_SERVER['HTTP_USER_AGENT']."\r\n" ) ); $context = stream_context_create($opts); $url = dynamic.12306.cn/...0$data = file_get_contents($url,null,$context);echo $data;?> 这样就可以了
纯自动录入,还是配合人手动。假如手动就简单多了,无非就是写个正则把页
面的url和标题搞下来。要是纯自动的,你必须写一段程序模拟出来你正常访问
情况,当你到达第一页的时候,是发送的一个POST请求,你需要发送相应参数
和POST请求过去,然后再页面截取相应的需要,当要访问第二版的时候,发送
的是GET请求,这个时候同理要发送参数过去条状,直到第十页。php管网上有
类似的爬虫类,去下个,很方便的

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Validator can be created by adding the following two lines in the controller.
