Recommend this page to a friend! |
PHP HTTP protocol client | > | All threads | > | HTTPS Upload File | > | (Un) Subscribe thread alerts |
|
1 - 10 | 11 - 20 | 21 - 30 |
![]() Hello! I am proving the example of the shipment of archives by means of POST, already have access to the servant of PEMEX, but now desire to know like sending the archives to the servant. use the code that is in this site but it does not work to me, please I need urgent aid…
![]() You just need to use the PostFiles request parameter. The test_http.php example script demonstrates how to use it. If it does not work for you, just let me know what happens, so I can advise.
![]() Thanks to answer, the following code is the one that I use to be able to have access to the site, but not like using the code for the shipment of archives very well.
<?php /* * send_http_post.php */ ?> <HTML> <HEAD> <TITLE>Envio a Pemex</TITLE> </HEAD> <BODY> <H1><CENTER>Envio a Pemex</CENTER></H1> <HR> <UL> <?php require("http.php"); require("sasl.php"); //****** it must load for the authentication **** set_time_limit(0); $http=new http_class; $http->timeout=0; $http->data_timeout=0; $http->debug=0; $http->html_debug=1; // **** lines added by authentication ******** $http->user_agent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"; $http->exclude_address=""; $user="0000111257"; $password="343f5e1853"; $realm=""; /* Authentication realm or domain */ $workstation=""; /* Workstation for NTLM authentication */ $authentication=(strlen($user) ? UrlEncode($user).":".UrlEncode($password)."@" : ""); //******************************** $url="https://".$authentication."convol.ref.pemex.com/php/sccvp001_01.php"; $error=$http->GetRequestArguments($url,$arguments); // **** lines added by authentication ******** if(strlen($realm)) $arguments["AuthRealm"]=$realm; if(strlen($workstation)) $arguments["AuthWorkstation"]=$workstation; $http->authentication_mechanism=""; // force a given authentication mechanism; $arguments["Headers"]["Pragma"]="nocache"; flush(); //************************************* $arguments["RequestMethod"]="POST"; ////* I do not understand the correct operation of these lines $arguments["PostValues"]=array( "somefield"=>"Upload forms", "MAX_FILE_SIZE"=>"1000000" ); $arguments["PostFiles"]=array( ////*I do not understand the correct operation of these lines "userfile"=>array( "Data"=>"This is just a plain text attachment file named attachment.txt .", "Name"=>"attachment.txt", "Content-Type"=>"automatic/name", ), "anotherfile"=>array( "FileName"=>"send_http_post.php", ////*I do not understand the correct operation of these lines "Content-Type"=>"automatic/name", ) ); $arguments["Referer"]="http://www.alltheweb.com/"; ////*I do not understand the correct operation of these lines echo "<H2><LI>Opening connection to:</H2>\n<PRE>",HtmlEntities($arguments["HostName"]),"</PRE>\n"; flush(); $error=$http->Open($arguments); if($error=="") { $error=$http->SendRequest($arguments); if($error=="") { echo "<H2><LI>Request:</LI</H2>\n<PRE>\n".HtmlEntities($http->request)."</PRE>\n"; echo "<H2><LI>Request headers:</LI</H2>\n<PRE>\n"; for(Reset($http->request_headers),$header=0;$header<count($http->request_headers);Next($http->request_headers),$header++) { $header_name=Key($http->request_headers); if(GetType($http->request_headers[$header_name])=="array") { for($header_value=0;$header_value<count($http->request_headers[$header_name]);$header_value++) echo $header_name.": ".$http->request_headers[$header_name][$header_value],"\r\n"; } else echo $header_name.": ".$http->request_headers[$header_name],"\r\n"; } echo "</PRE>\n"; echo "<H2><LI>Request body:</LI</H2>\n<PRE>\n".HtmlEntities($http->request_body)."</PRE>\n"; flush(); $headers=array(); $error=$http->ReadReplyHeaders($headers); if($error=="") { echo "<H2><LI>Response headers:</LI</H2>\n<PRE>\n"; for(Reset($headers),$header=0;$header<count($headers);Next($headers),$header++) { $header_name=Key($headers); if(GetType($headers[$header_name])=="array") { for($header_value=0;$header_value<count($headers[$header_name]);$header_value++) echo $header_name.": ".$headers[$header_name][$header_value],"\r\n"; } else echo $header_name.": ".$headers[$header_name],"\r\n"; } echo "</PRE>\n"; flush(); 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(); } } $http->Close(); } if(strlen($error)) echo "<CENTER><H2>Error: ",$error,"</H2><CENTER>\n"; ?> </UL> <HR> </BODY> </HTML> when executing it sends the following thing to me of answer Opening connection to: convol.ref.pemex.com Request: POST /php/sccvp001_01.php HTTP/1.1 Request headers: Host: convol.ref.pemex.com User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) Pragma: nocache Content-Type: multipart/form-data; boundary=--03ae1cc6f60e7cf29f09f729941ad749 Content-Length: 5878 Request body: Response headers: http/1.1 200 ok: date: Sat, 10 Feb 2007 02:01:48 GMT server: Apache/2.0.54 HP-UX_Apache-based_Web_Server (Unix) mod_ssl/2.0.54 OpenSSL/0.9.7g DAV/2 PHP/5.0.4 x-powered-by: PHP/5.0.4 content-length: 4106 connection: close content-type: text/html; charset=ISO-8859-1 Response body: <HTML> <HEAD> <META http-equiv="Content-Style-Type" content="text/css"> <META http-equiv="Pragma" content="no-cache"> <META http-equiv="Cache-Control" content="no-cache"> <LINK href="/php/imagenes/Portal_SIIC.css" rel="stylesheet" type="text/css"> <TITLE>Control volumétrico PEMEX REFINACION</TITLE> </HEAD> the following lines are those of the form that is in the PEMEX site, in where I must put the archives that desire to send, in addition to a text of 40 characters I hope you can help me, thanks friend
![]() The PostFiles parameter is an array that lists all form file inputs. The index of each array entry is the input name. The entry value is another array that describes from where the class will read the data of the files to upload.
If you only have one file to upload, your PostFiles definition may look like this: "PostFiles"=>array "my_file_input_name"=>array( "FileName"=>"file_name.txt", "Content-Type"=>"automatic/name" ) ) This makes a file in the machine the script is running named file_name.txt be uploaded to the server as value of the file input named my_file_input_name . The content type is guessed automatically by the class from the file name. In this case it will be text/plain because the file name extension is .txt , but you can override the type guessing by replacing the Content-Type parameter by something else other than automatic/name as it is above.
![]() hello! Analyze what I answer myself with respect to the shipment of archives, in where says to me that I must create script with the file_name.txt name in my machine, my question is, that has that file? it is there where has the names of the archives that I want to send? and to that one talks about by " my_file_input_name ". excuse by so many questions are new in this scope of work.
$arguments["RequestMethod"]="POST"; $arguments["PostValues"]=array( "somefield"=>"Upload forms", "MAX_FILE_SIZE"=>"10000" ); $arguments["PostFiles"]=array( "my_file_input_name"=>array( "FileName"=>"file_name.txt", "Content-Type"=>"automatic/name", ) ); I wait for its quick answer, thanks .....
![]() I am not sure what you are asking. The explanation above shows how you can send a file named file_name.txt to the server using an HTTP POST request.
That is the way to send any file that exists on the machine the script is running. If you want to upload more than one file, either you send multiple requests, or you send a request using several entries in the PostFiles array, one for each file, as long as the server can handle forms with multiple file upload inputs. In the example, the my_input_file_name corresponds to the name of a file form input. If you want to send more files at once, the form in the original page must have multiple file inputs, each with a different name. If that is the case, look at the HTML of the form to find the file inputs and the names that are used.
![]() The following code is the one that I occupy to send archives. I occupy seven input name with file attribute, seven input name with text attribute of 40 characters and one key of 10 characters.
///*I need to know if it is necessary that they fence these lines of code? $arguments["RequestMethod"]="POST"; $arguments["PostValues"]=array( "somefield"=>"Upload forms", "MAX_FILE_SIZE"=>"100" ); /********************************************************* --------------------------------------- So far single I use to send the seven input name with attribute cases out and the access key, as it is seen next: $arguments["RequestMethod"]="POST"; $arguments["PostValues"]=array( "clave"=>"343f5e1853" ); $arguments["PostFiles"]=array( "existencias"=>array( "FileName"=>"0000111948E07122VTA20070206.035801.gpg", "Content-Type"=>"automatic/name", ) ); $arguments["PostFiles"]=array( "recibo"=>array( "FileName"=>"0000111948E07122VTA20070206.035801.gpg", "Content-Type"=>"automatic/name", ) ); $arguments["PostFiles"]=array( "ventas"=>array( "FileName"=>"0000111948E07122VTA20070206.035801.gpg", "Content-Type"=>"automatic/name", ) ); $arguments["PostFiles"]=array( "alarmatanque"=>array( "FileName"=>"0000111948E07122VTA20070206.035801.gpg", "Content-Type"=>"automatic/name", ) ); $arguments["PostFiles"]=array( "alarmadispensario"=>array( "FileName"=>"0000111948E07122VTA20070206.035801.gpg", "Content-Type"=>"automatic/name", ) ); $arguments["PostFiles"]=array( "cattanque"=>array( "FileName"=>"0000111948E07122VTA20070206.035801.gpg", "Content-Type"=>"automatic/name", ) ); $arguments["PostFiles"]=array( "catdisp"=>array( "FileName"=>"0000111948E07122VTA20070206.035801.gpg", "Content-Type"=>"automatic/name", ) ); ---------------------------------- ************ and gave me this output********** Opening connection to: convol.ref.pemex.com Sending request for page: /php/sccvp001_01.php Login: 0000111257 Password: ********** Error: 5 could not send the HTTP request: Could not execute the request: SSL read: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number, errno 0 It excuses by so many questions but I am a new one in this atmosphere of work, thanks for everything.
![]() I am not sure what is causing the error below, but your PHP installation may have problems regarding SSL support.
Now for the file uploads, as I mentioned, either you send multiple separate requests to send one file at once, or you need to create a PostFiles array with all the inputs in the array, not defining the array several times as you have.
![]() the Array to create this way then?
$arguments["RequestMethod"]="POST"; $arguments["PostValues"]=array( "clave"=>"343f5e1853" ); $arguments["PostFiles"]=array( "existencias"=>array( "FileName"=>"0000111948E07122VTA20070206.035801.gpg", "Content-Type"=>"automatic/name", ) recibo"=>array( "FileName"=>"0000111948E07122VTA20070206.035801.gpg", "Content-Type"=>"automatic/name", ) "ventas"=>array( "FileName"=>"0000111948E07122VTA20070206.035801.gpg", "Content-Type"=>"automatic/name", ) "alarmatanque"=>array( "FileName"=>"0000111948E07122VTA20070206.035801.gpg", "Content-Type"=>"automatic/name", ) "alarmadispensario"=>array( "FileName"=>"0000111948E07122VTA20070206.035801.gpg", "Content-Type"=>"automatic/name", ) "cattanque"=>array( "FileName"=>"0000111948E07122VTA20070206.035801.gpg", "Content-Type"=>"automatic/name", ) "catdisp"=>array( "FileName"=>"0000111948E07122VTA20070206.035801.gpg", "Content-Type"=>"automatic/name", ) ); ********** the FileName is the name of the file that desire to command, truth? ***************** as far as the SSL in where I can badly see if the this connection with my PHP
![]() Hello! how are you? to me it even continues appearing he himself error when executing my code. the code that I use is the following one, I hope you can help me
<?php /* * send_http_post.php */ ?> <HTML> <HEAD> <TITLE>Envio a Pemex</TITLE> </HEAD> <BODY> <H1><CENTER>Envio a Pemex</CENTER></H1> <HR> <UL> <?php require("http.php"); require("sasl.php"); //****** it must load for the authentication **** set_time_limit(0); $http=new http_class; $http->timeout=0; $http->data_timeout=0; $http->debug=0; $http->html_debug=1; // **** lines added by authentication ******** $http->user_agent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"; $http->follow_redirect=1; /// agregado $http->redirection_limit=5; /// agregado $user="0000111257"; $password="343f5e1853"; $realm=""; /* Authentication realm or domain */ $workstation=""; /* Workstation for NTLM authentication */ $authentication=(strlen($user) ? UrlEncode($user).":".UrlEncode($password)."@" : ""); $http->exclude_address=""; $url="https://".$authentication."convol.ref.pemex.com/php/sccvp001_01.php"; $error=$http->GetRequestArguments($url,$arguments); if(strlen($realm)) $arguments["AuthRealm"]=$realm; if(strlen($workstation)) $arguments["AuthWorkstation"]=$workstation; $http->authentication_mechanism=""; // force a given authentication mechanism; $arguments["Headers"]["Pragma"]="nocache"; flush(); $arguments["RequestMethod"]="POST"; ////* I need to know if it is necessary that they fence these lines of code? $arguments["PostValues"]=array( ////* I need to know if it is necessary that they fence these lines of code? "somefield"=>"Upload forms", ////* I need to know if it is necessary that they fence these lines of code? "MAX_FILE_SIZE"=>"1000" ////* I need to know if it is necessary that they fence these lines of code? ); $arguments["RequestMethod"]="POST"; $arguments["PostValues"]=array( "clave"=>"343f5e1853" ); $arguments["PostFiles"]=array( "existencias"=>array( "FileName"=>"0000111948E07122VTA20070206.035801.gpg", "Content-Type"=>"automatic/name", ), "recibo"=>array( "FileName"=>"0000111948E07122VTA20070206.035801.gpg", "Content-Type"=>"automatic/name", ), "ventas"=>array( "FileName"=>"0000111948E07122VTA20070206.035801.gpg", "Content-Type"=>"automatic/name", ), "alarmatanque"=>array( "FileName"=>"0000111948E07122VTA20070206.035801.gpg", "Content-Type"=>"automatic/name", ), "alarmadispensario"=>array( "FileName"=>"0000111948E07122VTA20070206.035801.gpg", "Content-Type"=>"automatic/name", ), "cattanque"=>array( "FileName"=>"0000111948E07122VTA20070206.035801.gpg", "Content-Type"=>"automatic/name", ), "catdisp"=>array( "FileName"=>"0000111948E07122VTA20070206.035801.gpg", "Content-Type"=>"automatic/name", ) ); echo "<H2><LI>Opening connection to:</H2>\n<PRE>",HtmlEntities($arguments["HostName"]),"</PRE>\n"; flush(); $error=$http->Open($arguments); if($error=="") { echo "<H2><LI>Sending request for page:</H2>\n<PRE>"; echo HtmlEntities($arguments["RequestURI"]),"\n"; if(strlen($user)) echo "\nLogin: ",$user,"\nPassword: ",str_repeat("*",strlen($password)); echo "</PRE>\n"; flush(); $error=$http->SendRequest($arguments); if($error=="") { echo "<H2><LI>Request:</LI</H2>\n<PRE>\n".HtmlEntities($http->request)."</PRE>\n"; echo "<H2><LI>Request headers:</LI</H2>\n<PRE>\n"; for(Reset($http->request_headers),$header=0;$header<count($http->request_headers);Next($http->request_headers),$header++) { $header_name=Key($http->request_headers); if(GetType($http->request_headers[$header_name])=="array") { for($header_value=0;$header_value<count($http->request_headers[$header_name]);$header_value++) echo $header_name.": ".$http->request_headers[$header_name][$header_value],"\r\n"; } else echo $header_name.": ".$http->request_headers[$header_name],"\r\n"; } echo "</PRE>\n"; flush(); $headers=array(); $error=$http->ReadReplyHeaders($headers); if($error=="") { echo "<H2><LI>Response status code:</LI</H2>\n<P>".$http->response_status; switch($http->response_status) { case "301": case "302": case "303": case "307": echo " (redirect to <TT>".$headers["location"]."</TT>)<BR>\nSet the <TT>follow_redirect</TT> variable to handle redirect responses automatically."; break; } echo "</P>\n"; echo "<H2><LI>Response headers:</LI</H2>\n<PRE>\n"; for(Reset($headers),$header=0;$header<count($headers);Next($headers),$header++) { $header_name=Key($headers); if(GetType($headers[$header_name])=="array") { for($header_value=0;$header_value<count($headers[$header_name]);$header_value++) echo $header_name.": ".$headers[$header_name][$header_value],"\r\n"; } else echo $header_name.": ".$headers[$header_name],"\r\n"; } echo "</PRE>\n"; flush(); 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(); } } $http->Close(); } if(strlen($error)) echo "<CENTER><H2>Error: ",$error,"</H2><CENTER>\n"; ?> </UL> <HR> </BODY> </HTML> and the answer that I obtain is: *************** Opening connection to: convol.ref.pemex.com Sending request for page: /php/sccvp001_01.php Login: 0000111257 Password: ********** Error: 5 could not send the HTTP request: Could not execute the request: SSL read: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number, errno 0 |
1 - 10 | 11 - 20 | 21 - 30 |
info at phpclasses dot org
.