PHP獲取遠道文件
Jun 13, 2016 pm 01:24 PM
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下才有一次成功,其他都會出現(xiàn)一個警告,提示 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>

熱AI工具

Undress AI Tool
免費脫衣服圖片

Undresser.AI Undress
人工智能驅(qū)動的應(yīng)用程序,用于創(chuàng)建逼真的裸體照片

AI Clothes Remover
用于從照片中去除衣服的在線人工智能工具。

Clothoff.io
AI脫衣機

Video Face Swap
使用我們完全免費的人工智能換臉工具輕松在任何視頻中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的代碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
功能強大的PHP集成開發(fā)環(huán)境

Dreamweaver CS6
視覺化網(wǎng)頁開發(fā)工具

SublimeText3 Mac版
神級代碼編輯軟件(SublimeText3)

php blob轉(zhuǎn)file的方法:1、創(chuàng)建一個php示例文件;2、通過“function blobToFile(blob) {return new File([blob], 'screenshot.png', { type: 'image/jpeg' })}”方法實現(xiàn)Blob轉(zhuǎn)File即可。

使用Java的File.length()函數(shù)獲取文件的大小文件大小是在處理文件操作時很常見的一個需求,Java提供了一個很方便的方法來獲取文件的大小,即使用File類的length()方法。本文將介紹如何使用該方法來獲取文件的大小,并給出相應(yīng)的代碼示例。首先,我們需要創(chuàng)建一個File對象來表示我們想要獲取大小的文件。以下是創(chuàng)建File對象的方法:Filef

想了解更多關(guān)于開源的內(nèi)容,請訪問:51CTO鴻蒙開發(fā)者社區(qū)https://ost.51cto.com運行環(huán)境DAYU200:4.0.10.16SDK:4.0.10.15IDE:4.0.600一、創(chuàng)建應(yīng)用點擊File->newFile->CreateProgect。選擇模版:【OpenHarmony】EmptyAbility:填寫項目名,shici,應(yīng)用包名com.nut.shici,應(yīng)用存儲位置XXX(不要有中文,特殊字符,空格)。CompileSDK10,Model:Stage。Device

機器之能報道編輯:吳昕國內(nèi)版的人形機器人+大模型組隊,首次完成疊衣服這類復(fù)雜柔性材料的操作任務(wù)。隨著融合了OpenAI多模態(tài)大模型的Figure01揭開神秘面紗,國內(nèi)同行的相關(guān)進展一直備受關(guān)注。就在昨天,國內(nèi)"人形機器人第一股"優(yōu)必選發(fā)布了人形機器人WalkerS深入融合百度文心大模型后的首個Demo,展示了一些有趣的新功能?,F(xiàn)在,得到百度文心大模型能力加持的WalkerS是這個樣子的。和Figure01一樣,WalkerS沒有走動,而是站在桌子后面完成一系列任務(wù)。它可以聽從人類的命令,折疊衣物

使用Java的File.renameTo()函數(shù)重命名文件在Java編程中,我們經(jīng)常需要對文件進行重命名的操作。Java提供了File類來處理文件操作,其中的renameTo()函數(shù)可以方便地重命名文件。本文將介紹如何使用Java的File.renameTo()函數(shù)來重命名文件,并提供相應(yīng)的代碼示例。File.renameTo()函數(shù)是File類的一個方法,

如果您是IT管理員或技術(shù)專家,您一定意識到自動化的重要性。尤其對于Windows用戶來說,MicrosoftPowerShell是最佳的自動化工具之一。微軟為滿足您的自動化需求提供了各種工具,無需安裝第三方應(yīng)用程序。本指南將詳細介紹如何利用PowerShell自動化執(zhí)行任務(wù)。什么是PowerShell腳本?如果您有使用PowerShell的經(jīng)驗,您可能已經(jīng)使用過命令來配置您的操作系統(tǒng)。腳本是.ps1文件中這些命令的集合。.ps1文件包含由PowerShell執(zhí)行的腳本,例如基本的Get-Help

使用java的File.getParent()函數(shù)獲取文件的父路徑在Java編程中,我們經(jīng)常需要操作文件和文件夾。有時候,我們需要獲取一個文件的父路徑,也就是該文件所在文件夾的路徑。Java的File類提供了getParent()方法用于獲取文件或文件夾的父路徑。File類是Java對文件和文件夾的抽象表示,它提供了一系列操作文件和文件夾的方法。其中,get

一、java調(diào)用post接口1、使用URLConnection或者HttpURLConnectionjava自帶的,無需下載其他jar包URLConnection方式調(diào)用,如果接口響應(yīng)碼被服務(wù)端修改則無法接收到返回報文,只能當(dāng)響應(yīng)碼正確時才能接收到返回publicstaticStringsendPost(Stringurl,Stringparam){OutputStreamWriterout=null;BufferedReaderin=null;StringBuilderresult=newSt
