curl: posting form variables results in redirection

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • TJ Talluto

    curl: posting form variables results in redirection

    Hi,
    I'm using the curl functions in php to scrape the wan ip address from my
    home router (the router is an SMC product). This is a two step process:
    1. post the password value to the login.htm page
    2. capture and parse the content from the status_main.htm page

    On the SMC's login.htm page there is a form with the following elements:
    <form name=tF method=post action=login.ht m>
    <input type=password name=pws>
    <input type=hidden name=page value=login>
    <submit value='LOGIN'>

    Here are three test cases - only the first two work as expected. I need to
    understand why I got that third response... posting the variables causes a
    the SMC to give me a redirection to index.htm which does not exist?

    COMMAND LINE TEST (returns login.htm and status_main.htm accurately):
    curl -d page=login.htm -d pws=mypassword http://10.10.10.1/login.htm
    curl http://10.10.10.1/status_main.htm | grep 'wan_ip'

    PHP NO-POST TEST(returns login.htm accurately):
    $ch = curl_init("http ://10.10.10.1/login.htm");
    $strIP = curl_exec($ch);
    curl_close($ch) ;

    PHP POST TEST (returns an unexpected result):
    $ch = curl_init("http ://10.10.10.1/login.htm");
    curl_setopt($ch , CURLOPT_POST, 1);
    curl_setopt($ch , CURLOPT_POSTFIE LDS, "page=login&pws =mypassword");
    curl_setopt($ch , CURLOPT_RETURNT RANSFER, 1);
    $strIP = curl_exec($ch);
    curl_close($ch) ;
    print "<!-- $strIP -->";

    <!-- <html><head><me ta http-equiv=refresh content='0;
    url=/index.htm'></head></html> -->


    --
    TJ Talluto
    torpedo51 at yahoo dot com
  • TJ Talluto

    #2
    Re: curl: posting form variables results in redirection

    > <!-- <html><head><me ta http-equiv=refresh content='0;[color=blue]
    > url=/index.htm'></head></html> -->[/color]

    I have now verified that this is the correct redirection for the first
    request (POSTing the variables)... but strangely the second request (GET)
    returns the same string. I suspect that subsequent calls are not handled
    properly by the curl module... Anyone?

    --
    TJ Talluto
    torpedo51 at yahoo dot com

    Comment

    • Manuel Lemos

      #3
      Re: curl: posting form variables results in redirection

      Hello,

      On 11/01/2004 11:10 PM, TJ Talluto wrote:[color=blue][color=green]
      >><!-- <html><head><me ta http-equiv=refresh content='0;
      >>url=/index.htm'></head></html> -->[/color]
      >
      >
      > I have now verified that this is the correct redirection for the first
      > request (POSTing the variables)... but strangely the second request (GET)
      > returns the same string. I suspect that subsequent calls are not handled
      > properly by the curl module... Anyone?[/color]

      Probably it is not collecting cookies or handling redirection as needed.

      You may want to try this HTTP client class that can do that properly and
      let me know if it does not solve the problem.




      --

      Regards,
      Manuel Lemos

      PHP Classes - Free ready to use OOP components written in PHP
      Free PHP Classes and Objects 2026 Versions with PHP Example Scripts, PHP Tutorials, Download PHP Scripts, PHP articles, Remote PHP Jobs, Hire PHP Developers, PHP Book Reviews, PHP Language OOP Materials


      PHP Reviews - Reviews of PHP books and other products


      Metastorage - Data object relational mapping layer generator

      Comment

      Working...