Recommend this page to a friend! |
PHP HTTP protocol client | > | All threads | > | download file with post | > | (Un) Subscribe thread alerts |
|
Fernando - 2006-05-16 06:21:55
Hi:
I'm traying to get a xls file through post, i made changes to a vars $url,$arguments["PostValues"] and $arguments["Referer"] and it's working fine(gracias Manuel :=) ), but i need to download the file so need your help, tell me how can i convert response o how get response as a file. thank you! those are response headers and response body(a part of it) Response headers: http/1.1 200 ok: cache-control: must-revalidate, post-check=0,pre-check=0 pragma: public content-type: application/vnd.ms-excel expires: 0 server: Microsoft-IIS/6.0 x-powered-by: PHP/4.3.10 x-powered-by: ASP.NET content-disposition: attachment; filename=precios Aji.xls microsoftofficewebserver: 5.0_Pub date: Tue, 16 May 2006 05:56:52 GMT connection: close Response body: ࡱ> )* l PreciosAji=%r8X"1Arial1Arial1Arial1Arial1Arial1Arial1 Arial1Arial H H 83ffff̙̙3f3̙fff3f3f33333f33333 PreciosAji l *+"dXX?? Y XPltimo Precio pagado por los distintos poderes compradores para el producto: AjiRegin ProvinciaPoder Comprador FechaVariedadCalidad Unidad MedidaMoneda Precio Mximo Precio Mnimo Precio Comn IV Elqui$Feria Mayorista Las Palmeras 2001-11-02 AmericanoPrimeraPeso IV Elqui$Feria Mayorista Las Palmeras 2005-12-19 AmericanoPrimeraKiloPesou@ y@ y@ IV Elqui$Feria Mayorista Las Palmeras 2005-10-19 AmericanoSegundaKiloPeso@@ @ @ IV Elqui$Feria Mayorista Las Palmeras 2001-12-14CristalPrimeraPeso IV Elqui$Feria Mayorista Las Palmeras 2002-08-21CristalPrimera Caja 30 KilosPeso @ @ @ IV Elqui$Feria Mayorista Las Palmeras 2002-12-04CristalPrimeraKiloPesor@ y@ u@ IV Elqui$Feria Mayorista Las Palmeras 2002-11-07CristalSegundaPeso IV Elqui$ Feria Mayorista Las Palmeras 2002-08-21 Cristal Segunda Caja 30 Kilos Peso @ @ @ IV Elqui$ Feria Mayorista Las Palmeras 2002-11-21 Cristal Segunda Kilo Peso y@ y@ y@ IV Elqui$Feria Mayorista Las Palmeras 2002-09-02CristalTerceraKiloPeso@@ @@ @@ IV Elqui$Feria Mayorista Las Palmeras 2002-12-30Cristal AmericaPrimeraKiloPeso`@ @ @ IV Elqui$ Feria Mayorista Las Palmeras 2002-12-23 Cristal America Segunda Kilo Peso @@ @@ @@ IV Elqui$Feria Mayorista Las Palmeras 2002-11-25InfiernoPrimeraKiloPesoy@ y@ y@ IV Elqui$Feria Mayorista Las Palmeras 2005-04-20Sin EspecificaPrimeraKiloPesoy@ @@ |@ IV Elqui$Feria Mayorista Las Palmeras 2006-04-21Sin EspecificarPrimeraKiloPesor@ r@ r@ IVLimar)!Feria Mayorista El Agro de Limar 2001-06-22KiloPeso@ @ @ IVLimar)!Feria Mayorista El Agro de Limar 2001-05-25PrimeraKiloPesoi@ i@ i@ IVLimar)!Feria Mayorista El Agro de Limar 2001-11-02 AmericanoPrimeraPeso IVLimar)!Feria Mayorista El Agro de Limar 2006-05-10 AmericanoPrimera Caja 30 KilosPesoX@ X@ X@ IVLimar)!Feria Mayorista El Agro de Limari 2005-08-12 AmericanoPrimeraKiloPeso333333? 333333? 333333? IVLimar)!Feria Mayorista El Agro de Limar 2001-06-20 AmericanoPrimeraKiloPeso@@ @ @@ IVLimar)!Feria Mayorista El Agro de Limar 2001-12-14CRISTALPrimeraPeso IVLimar)!Feria Mayorista El Agro de Limari 2002-12-04CristalPrimera Caja 30 KilosPesop@ p@ p@ IVLimar)!Feria Mayorista El Agro de Limar 2001-03-21CRISTALPrimera Caja 30 KilosPeso@ @ @ IVLimar)!Feria Mayorista El Agro de Limar 2002-11-07CRISTALPrimeraKiloPesou@ u@ u@ IVLimar)!Feria Mayorista El Agro de Limari 2002-04-22CristalPrimeraKiloPesoQ@ Q@ Q@ IVLimar)!Feria Mayorista El Agro de Limar 2001-12-28CRISTALPrimeraKiloPesoy@ y@ y@ IVLimar)!Feria Mayorista El Agro de Limari 2001-01-28CristalPrimeraKiloPesof@ f@ f@ IVLimar)!Feria Mayorista El Agro de Limar 2001-01-26CRISTALPrimeraKiloPesob@ b@ b@ IVLimar)!Feria Mayorista El Agro de Limar 2002-11-07CRISTALSegundaPeso IV Limar) !Feria Mayorista El Agro de Limari 2002-11-21 Cristal Segunda
Manuel Lemos - 2006-05-17 02:15:32 - In reply to message 1 from Fernando
I am not sure what is the difficulty. If you want to download a file and store it in a local file, just keep reading the response body with the function ReadReplyBody and write the data to your local file.
Fernando - 2006-05-17 04:57:28 - In reply to message 2 from Manuel Lemos
Ok thanks for help me, i made this code:
$error=$http->ReadReplyBody($body,1000); if($error!=""|| strlen($body)==0) break; $gestor = fopen("J:\precios Aji.xls", "w"); fwrite($gestor, $body); fclose($gestor); But xls format is wrong, the file created shows a book with rows like this: 2002-04-15ICristalIPrimeraIKiloIPesoI@o@I As you can see, rows are not divided by columns 2002-04-15,Cristal,Primera,etc.. I really appreciate your help
Manuel Lemos - 2006-05-17 05:20:49 - In reply to message 3 from Fernando
You need to include that code in a loop so you can copy the whole file, not just the first 1000 bytes.
Also you need to use the mode "wb" when writing to binary files, or else you file may become corrupted.
Fernando - 2006-05-17 07:41:49 - In reply to message 4 from Manuel Lemos
GOTCHA!!!
ok, i fixed my code, thanks to MANUEL LEMOS (gracias loco, te pasaste de wena onda!!) so to get a xml file through a post form i made some changes to test_http_post.php, file included with "http protocol client class", vars changed: $url // giving site url $arguments["PostValues"] // pairs variable/value $arguments["Referer"] // request page and code changes in the response section, replacing this: echo "<H2><LI>Response body:</LI</H2>\n<PRE>\n"; for(;;) { $error=$http->ReadReplyBody($body,1000); if($error!="" || strlen($body)==0) break; echo HtmlSpecialChars($body); } echo "</PRE>\n"; flush(); to this: echo "<H2><LI>Response body:</LI</H2>\n<PRE>\n"; $bodyx=""; // initializing body for(;;) { $error=$http->ReadReplyBody($body,100000); if($error!="" || strlen($body)==0) break; $bodyx.=$body; // adding new parts from loop } $gestor = fopen("J:\precios Aji.xls", "wb"); // opening or creating file with write and binary options fwrite($gestor, $bodyx); // writing complete body fclose($gestor); // closing file echo "</PRE>\n"; flush(); that's all chao pescao
Fernando - 2006-05-17 07:48:48 - In reply to message 5 from Fernando
update, fe de erratas.
change "...to get a xml file through..." to "...to get a xls file through..." on last reply....oops...jeje ;-), sorry bye, chao |
info at phpclasses dot org
.