PHP获取远道文件
PHP获取远程文件
if(!($contents=file_get_contents('http://finance.yahoo.com/d/quotes.csv?s=AMZN&e=.csv&f=slldltlclohgv'))){
die('fail to open yahoo');
};
echo $contents;
为什么平均要刷新3-4下才有一次成功,其他都会出现一个警告,提示 HTTP request failed!
------解决方案--------------------
- C/C++ code
Bart Friederichs 16-Apr-2012 12:17 file_get_contents can do a POST, create a context for that first: $opts = array('http' => array( 'method' => 'POST', 'header' => "Content-Type: text/xml\r\n". "Authorization: Basic ".base64_encode("$https_user:$https_password")."\r\n", 'content' => $body, 'timeout' => 60 ) ); $context = stream_context_create($opts); $url = 'https://'.$https_server; $result = file_get_contents($url, false, $context, -1, 40000); pperegrina 21-Dec-2011 11:30 For those having this problem when trying to get_file_contents(url): Warning: file_get_contents(url): failed to open stream: HTTP request failed! in xx on line yy If you are behind a SonicWall firewall, read this: https://bugs.php.net/bug.php?id=40197 (this little line: uncheck a box in the internal settings of the firewall labled "Enforce Host Tag Search with for CFS") Apparently by default SonicWall blocks any HTTP request without a "Host:" header, which is the case in the PHP get_file_contents(url) implementation. This is why, if you try to get the same URL from the same machine with cURL our wget, it works. I hope this will be useful to someone, it took me hours to find out :) godwraith01 at yahoo dot com 11-Oct-2011 04:16 I experienced a problem in using hostnames instead straight IP with some server destinations. If i use file_get_contents("www.jbossServer.example/app1",...) i will get an 'Invalid hostname' from the server i'm calling. This is because file_get_contents probably will rewrite your request after getting the IP, obtaining the same thing as : file_get_contents("xxx.yyy.www.zzz/app1",...) And you know that many servers will deny you access if you go through IP addressing in the request. With cURL this problem doesn't exists. It resolves the hostname leaving the request as you set it, so the server is not rude in response. <div class="clear"> </div>

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

To learn more about open source, please visit: 51CTO Hongmeng Developer Community https://ost.51cto.com Running environment DAYU200:4.0.10.16SDK: 4.0.10.15IDE: 4.0.600 1. To create an application, click File- >newFile->CreateProgect. Select template: [OpenHarmony] EmptyAbility: Fill in the project name, shici, application package name com.nut.shici, and application storage location XXX (no Chinese, special characters, or spaces). CompileSDK10, Model: Stage. Device

Use Java's File.length() function to get the size of a file. File size is a very common requirement when dealing with file operations. Java provides a very convenient way to get the size of a file, that is, using the length() method of the File class. . This article will introduce how to use this method to get the size of a file and give corresponding code examples. First, we need to create a File object to represent the file we want to get the size of. Here is how to create a File object: Filef

How to convert php blob to file: 1. Create a php sample file; 2. Through "function blobToFile(blob) {return new File([blob], 'screenshot.png', { type: 'image/jpeg' })} ” method can be used to convert Blob to File.

Use Java's File.renameTo() function to rename files. In Java programming, we often need to rename files. Java provides the File class to handle file operations, and its renameTo() function can easily rename files. This article will introduce how to use Java's File.renameTo() function to rename files and provide corresponding code examples. The File.renameTo() function is a method of the File class.

Editor of Machine Power Report: Wu Xin The domestic version of the humanoid robot + large model team completed the operation task of complex flexible materials such as folding clothes for the first time. With the unveiling of Figure01, which integrates OpenAI's multi-modal large model, the related progress of domestic peers has been attracting attention. Just yesterday, UBTECH, China's "number one humanoid robot stock", released the first demo of the humanoid robot WalkerS that is deeply integrated with Baidu Wenxin's large model, showing some interesting new features. Now, WalkerS, blessed by Baidu Wenxin’s large model capabilities, looks like this. Like Figure01, WalkerS does not move around, but stands behind a desk to complete a series of tasks. It can follow human commands and fold clothes

If you are an IT administrator or technology expert, you must be aware of the importance of automation. Especially for Windows users, Microsoft PowerShell is one of the best automation tools. Microsoft offers a variety of tools for your automation needs, without the need to install third-party applications. This guide will detail how to leverage PowerShell to automate tasks. What is a PowerShell script? If you have experience using PowerShell, you may have used commands to configure your operating system. A script is a collection of these commands in a .ps1 file. .ps1 files contain scripts executed by PowerShell, such as basic Get-Help

Use java's File.getParentFile() function to get the parent directory of a file. In Java programming, we often need to operate files and folders. When we need to get the parent directory of a file, we can use the File.getParentFile() function provided by Java. This article explains how to use this function and provides code examples. File class in Java is the main class used to operate files and folders. It provides many methods to obtain and manipulate file properties

Use java's File.getParent() function to get the parent path of a file. In Java programming, we often need to operate files and folders. Sometimes, we need to get the parent path of a file, which is the path of the folder where the file is located. Java's File class provides the getParent() method to obtain the parent path of a file or folder. The File class is Java's abstract representation of files and folders. It provides a series of methods for operating files and folders. Among them, get
