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 |
![]() Hi !.
I have to send files, to a certain https url. The thing is, I have to process those files, Log me in that site, and transmit those files with "POST" method. How I connect with the site ? /////////////////////////////////////////////////// 1) That way ?? //////////////////////////////////// ///////////////////////////////////////////////// require("http.php"); require("sasl.php"); set_time_limit(0); $http=new http_class; $http->timeout=0; $http->data_timeout=0; $http->debug=1; $http->html_debug=1; $http->user_agent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"; $http->follow_redirect=1; $http->redirection_limit=5; $http->exclude_address=""; $user="login"; $password="password"; $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_02.php"; $error=$http->GetRequestArguments($url,$arguments); if(strlen($realm)) $arguments["AuthRealm"]=$realm; if(strlen($workstation)) $arguments["AuthWorkstation"]=$workstation; $http->authentication_mechanism=""; $arguments["Headers"]["Pragma"]="nocache"; $error=$http->Open($arguments); $error=$http->SendRequest($arguments); ////////////////////////////////////////////// 2) Or That way ??//////////////////////////// ///////////////////////////////////////////// set_time_limit(0); $http=new http_class; $http->timeout=0; $http->data_timeout=0; $http->debug=1; $http->html_debug=1; $http->follow_redirect=1; $http->user_agent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"; $url="https://convol.ref.pemex.com/php/sccvp001_02.php"; $error=$http->GetRequestArguments($url,$arguments); $arguments["RequestMethod"]="POST"; $arguments["PostValues"]=array( "login_name" => "login", "passwd" => "password" ); ///////////////////////////////////////////////////// /////////////////////////////////////////////////// I'm pretty new at this matter, and even I don't have now the right password to connect to the site, the answer I get is "401 Authentication Required". So I don't know if the message is from bad password, or just the site doesn't receive the login. I have php 5.1.4, Apache 2.0.55, windows 2000, extension=php_openssl.dll in my php.ini and library sasl.php, basic_sasl_client.php, http.php Someone can help ?? Regards !
![]() ////////////////////////////////////////////////////////////
///////This is the answer I'm Getting in case number 1)/////// /////////////////////////////////////////////////////////////// Request headers: Host: convol.ref.pemex.com User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) Pragma: nocache S HTTP/1.1 401 Authorization Required S Date: Thu, 25 Jan 2007 13:41:11 GMT S 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 S WWW-Authenticate: Basic realm="Controles Volumetricos" S Content-Length: 563 S Connection: close S Content-Type: text/html; charset=iso-8859-1 S S <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>401 Authorization Required</title> </head><body> <h1>Authorization Required</h1> <p>This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't understand how to supply the credentials required.</p> <hr> <address>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 Server at convol.ref.pemex.com Port 443</address> </body></html> Disconnected from convol.ref.pemex.com Connecting to convol.ref.pemex.com Resolving HTTP server domain "convol.ref.pemex.com"... Connecting to HTTP server IP 200.23.91.39... Connected to convol.ref.pemex.com C GET /php/sccvp001_02.php HTTP/1.1 C Host: convol.ref.pemex.com C User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) C Pragma: nocache C Authorization: Basic Y29udm9sOmNvbnZvbA== C S HTTP/1.1 401 Authorization Required S Date: Thu, 25 Jan 2007 13:41:12 GMT S 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 S WWW-Authenticate: Basic realm="Controles Volumetricos" S Content-Length: 563 S Connection: close S Content-Type: text/html; charset=iso-8859-1 S Disconnected from convol.ref.pemex.com Error: Could not process the SASL authentication step: Basic authentication was finished without success
![]() This means that the class is accessing the page with the user and password that you specified, but those credentials are not accepted by the server.
It seems the user and password values you used are incorrect. Have you tried to access that server page with the browser with the same user and password? Did it show different results or keeps asking for the user and password again?
![]() Manuel, tanks for your incredible quick answer.
I've entered the login and password, accesing the page from the browser, and keeps me asking the login and password, of course. The login and password..... I don't know them, right now. I've just wanted to know that I was on the right way, and seeing your answer, I guess so. I'm sure I will ask you other things in the very near future !!. Thanks !.
![]() Manuel:
Now I've got the right user and password. When I log in thru the browser, everything goes ok, and take me to a screen. But when I do the operation with the script, it returns 401 error. The Script: require("http.php"); require("sasl.php"); set_time_limit(0); $http=new http_class; $http->timeout=0; $http->data_timeout=0; $http->debug=1; $http->html_debug=1; $http->user_agent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"; $http->exclude_address=""; $user="0000110815"; $password="bb6c69deef"; $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); 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(); $error=$http->Open($arguments); ///////////////////////////////////////////////// /////// and gave me this output////////////////// ///////////////////////////////////////////////// Opening connection to: convol.ref.pemex.com Connecting to convol.ref.pemex.com Resolving HTTP server domain "convol.ref.pemex.com"... Connecting to HTTP server IP 200.23.91.39... Connected to convol.ref.pemex.com Sending request for page: /php/sccvp001_01.php Login: 0000110815 Password: ********** C GET /php/sccvp001_01.php HTTP/1.1 C Host: convol.ref.pemex.com C User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) C Pragma: nocache C Request: GET /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 S HTTP/1.1 401 Authorization Required S Date: Fri, 02 Feb 2007 19:57:23 GMT S 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 S WWW-Authenticate: Basic realm="Controles Volumetricos" S Content-Length: 563 S Connection: close S Content-Type: text/html; charset=iso-8859-1 S S <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>401 Authorization Required</title> </head><body> <h1>Authorization Required</h1> <p>This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't understand how to supply the credentials required.</p> <hr> <address>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 Server at convol.ref.pemex.com Port 443</address> </body></html> Disconnected from convol.ref.pemex.com Connecting to convol.ref.pemex.com Resolving HTTP server domain "convol.ref.pemex.com"... Connecting to HTTP server IP 200.23.91.39... Connected to convol.ref.pemex.com C GET /php/sccvp001_01.php HTTP/1.1 C Host: convol.ref.pemex.com C User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) C Pragma: nocache C Authorization: Basic MDAwMDExMDgxNTpiYjZjNjlkZWVm C S HTTP/1.1 200 OK S Date: Fri, 02 Feb 2007 19:57:25 GMT S 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 S X-Powered-By: PHP/5.0.4 S Content-Length: 4106 S Connection: close S Content-Type: text/html; charset=ISO-8859-1 S Response status code: 200 Response headers: http/1.1 200 ok: date: Fri, 02 Feb 2007 19:57:25 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: S <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>
![]() Manuel:
Now I've got the right user and password. When I log in thru the browser, everything goes ok, and take me to a screen. But when I do the operation with the script, it returns 401 error. The Script: require("http.php"); require("sasl.php"); set_time_limit(0); $http=new http_class; $http->timeout=0; $http->data_timeout=0; $http->debug=1; $http->html_debug=1; $http->user_agent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"; $http->exclude_address=""; $user="0000110815"; $password="bb6c69deef"; $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); 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(); $error=$http->Open($arguments); ///////////////////////////////////////////////// /////// and gave me this output////////////////// ///////////////////////////////////////////////// Opening connection to: convol.ref.pemex.com Connecting to convol.ref.pemex.com Resolving HTTP server domain "convol.ref.pemex.com"... Connecting to HTTP server IP 200.23.91.39... Connected to convol.ref.pemex.com Sending request for page: /php/sccvp001_01.php Login: 0000110815 Password: ********** C GET /php/sccvp001_01.php HTTP/1.1 C Host: convol.ref.pemex.com C User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) C Pragma: nocache C Request: GET /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 S HTTP/1.1 401 Authorization Required S Date: Fri, 02 Feb 2007 19:57:23 GMT S 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 S WWW-Authenticate: Basic realm="Controles Volumetricos" S Content-Length: 563 S Connection: close S Content-Type: text/html; charset=iso-8859-1 S S <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>401 Authorization Required</title> </head><body> <h1>Authorization Required</h1> <p>This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't understand how to supply the credentials required.</p> <hr> <address>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 Server at convol.ref.pemex.com Port 443</address> </body></html> Disconnected from convol.ref.pemex.com Connecting to convol.ref.pemex.com Resolving HTTP server domain "convol.ref.pemex.com"... Connecting to HTTP server IP 200.23.91.39... Connected to convol.ref.pemex.com C GET /php/sccvp001_01.php HTTP/1.1 C Host: convol.ref.pemex.com C User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) C Pragma: nocache C Authorization: Basic MDAwMDExMDgxNTpiYjZjNjlkZWVm C S HTTP/1.1 200 OK S Date: Fri, 02 Feb 2007 19:57:25 GMT S 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 S X-Powered-By: PHP/5.0.4 S Content-Length: 4106 S Connection: close S Content-Type: text/html; charset=ISO-8859-1 S Response status code: 200 Response headers: http/1.1 200 ok: date: Fri, 02 Feb 2007 19:57:25 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: S <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>
![]() When the server requires authentication, it returns the status 401. Then the class sends the request again with the authentication user and password. If the user and password are correct, it returns the status 200, as you may the in the end. So all is working as expected for you.
![]() ok !!. Thanks !!
![]() Manuel, now I have to send files via http post.
So, I succesfully connect with the site, and I filled the $arguments array in this way: $arguments["RequestMethod"]="POST"; $arguments["PostValues"]=array( "clave"=>"ju85485LOK" ); $arguments["PostFiles"]=array( "alarmadispensario"=>array( "FileName"=>"somefile.gpg", "Content-Type"=>"automatic/name", ) ); In the documentation, says the attribute for the file should be "alarmadispensario", and there is another attribute related with this file called "alarmadispensario_checksum", of type "text". I'm not sending, because I want to the site gives me some kind of error, so I know how to read it. They say "send the files thru POST method with the attributes already described, according to types "file" and "text". Other attribute I must send is "clave". The response headers obtained are always "OK" with code 200. The page receiving all the data, is a php form, like that: ////////////////////////////////////////////// /////////////////////////////////////////////////////// <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> <BODY leftmargin="0" topmargin="0" marginwidth="0" marginheight="0"> <table align="center" width="775" cellspacing="0" cellpadding="0" border="0"> <tr> <td align="left"> <table cellSpacing="0" cellPadding="0" width="100%" border="0"> <tr> <td align="left" width="164" height="81"> <input type="image" name="menu_home" src="/php/imagenes/logopemexint_A.jpg" width="164" height="100%" border="0"> </td> <td vAlign="top" width="100%" height="81" background="/php/imagenes/continua_logo_B.jpg"> <table width="100%" height="100%" cellpadding="0" cellspacing="0" border="0"> <tr> <td class="textoBienvenida" vAlign="Center" align="Center" colspan="3" width="100%"> Envío de archivos de control volumétrico </td> </tr> </table> </td> </tr> </table> </td> </tr> <tr> <td colspan="2"> <form enctype="multipart/form-data" action="sccvp001_02.php" method="POST"> <table align="Center"> <tr> <td align="left" colspan="4"> <table> <tr><BR><BR> <th>Clave :</th><td><input name="clave" type="password" size="10" maxlength="10"/></td> </tr> </table> </td> </tr> <tr> <th>Alarma en dispensarios</th><td><input name="alarmadispensario" type="file" size="80" /></td><td><input name="alarmadispensario_checksum" type="text" size="45" MAXLENGTH=40/></td> </tr> <tr> <tr> <td colspan="3" align="center"><input type="submit" value="Enviar archivos" /></td> </tr> </table> </form> </td> </tr> </table> </body> </html> ////////////////////////////////////////////////// ///////////////////////////////////////////////// So, I know I'm doing something wrong, because I should receive an error code, but I'm receiving an "OK".
![]() It seems the site is assuming you are not sending the form because you are missing the alarmadispensario_checksum value. I think you always need to include that value to make the site process the form.
|
1 - 10 | 11 - 20 | 21 - 30 |
info at phpclasses dot org
.