Login   Register  
PHP Classes
elePHPant
Icontem

keeping the connection alive

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us

      PHP HTTP protocol client  >  All threads  >  keeping the connection alive  >  (Un) Subscribe thread alerts  
Subject:keeping the connection alive
Summary:submitting multiple forms after login to ssl site
Messages:5
Author:Ethan
Date:2005-07-15 15:41:49
Update:2005-08-12 01:48:19
 

  1. keeping the connection alive   Reply  
Picture of Ethan
Ethan
2005-07-15 15:41:49
Hi,

I've managed to successfully use your class to remotely log into my secured ssl site. After I have logged in, I need to have the class submit another form. Creating another instance of the class does not work because it looses the session and the system returns the login screen again. If I just add another set of GetRequestArguments with the new page url and post values, Open, SendRequest, and ReadReplyBody it returns only the first response (the successful login). I must be missing a fundamental part. Any help would be greatly appreciated. I'm the same guy that posted the "https post issue" post. Thanks for fixing that by the way.

Here is a summary of the working code I am using so far:

require("http.php");

set_time_limit(0);
$http=new http_class;
$http->timeout=0;
$http->data_timeout=0;
$http->debug=0;
$http->html_debug=1;
$http->follow_redirect=1;
$http->user_agent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
$url="MY_URL_IS_HERE";
$error=$http->GetRequestArguments($url,$arguments);
$arguments["RequestMethod"]="POST";
$arguments["PostValues"]=array(
MY_POST_VALUES_ARE_HERE
);
$error=$http->Open($arguments);
$error=$http->SendRequest($arguments);

MY_READ_REPLY_CODE_IS_HERE

So what do I do now if I want to submit a form that is on the resulting page without loosing the session.


  2. Re: keeping the connection alive   Reply  
Picture of Manuel Lemos
Manuel Lemos
2005-07-15 17:32:56 - In reply to message 1 from Ethan
You should be able to reuse the same object to submit another request for another page of the site. The class should send back any collected cookies, so it should not be redirected to the login page again.

If that does not work, you need to enable the debug mode to see what actually happens when you send the second request to another page of the same site using the same HTTP class object.

  3. Re: keeping the connection alive   Reply  
Picture of Ethan
Ethan
2005-08-11 23:36:56 - In reply to message 2 from Manuel Lemos
Hi,

Okay. I get the following error: "Error: 2 can not send request in the current connection state" - What does this mean?

Below is the code I am using to make the two requests. Am I missing something?

require("http.php");

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="MY_URL_IS_HERE";
$error=$http->GetRequestArguments($url,$arguments);
$arguments["RequestMethod"]="POST";
$arguments["PostValues"]=array(
MY_POST_VALUES_ARE_HERE
);
$error=$http->Open($arguments);
$error=$http->SendRequest($arguments);

END_OF_FIRST_REQUEST_AND_START_OF_SECOND_REQUEST

$url="MY_URL_IS_HERE";
$error=$http->GetRequestArguments($url,$arguments);
$arguments["RequestMethod"]="POST";
$arguments["PostValues"]=array(
MY_POST_VALUES_ARE_HERE
);
$error=$http->Open($arguments);
$error=$http->SendRequest($arguments);

MY_READ_REPLY_CODE_IS_HERE

$http->Close();

if(strlen($error))
print "<H2>Error: ",$error,"</H2>";

  4. Re: keeping the connection alive   Reply  
Picture of Manuel Lemos
Manuel Lemos
2005-08-12 00:22:54 - In reply to message 3 from Ethan
You get that message when you try to Send a request to a connection that was not correctly opened or is not in a state ready to send the request.

Looking at your code, it seems you are ignoring the eventual errors that may happen. Take a look at what the class state variable says.

It seems that you need to call the class Close() function before you can call the Open() function again.

  5. Re: keeping the connection alive   Reply  
Picture of Ethan
Ethan
2005-08-12 01:48:19 - In reply to message 4 from Manuel Lemos
Yes. I forgot to include the close statement. It works perfectly now. Thank you very much!