[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Handling a 302 Error
Hi Shannon,
302 isn't an error, it's a redirect. The site wants you to go to
another site.
I realize that other utilities handle redirects for you -- HTTPAPI on
the other hand is really intended to be a program-controlled tool -- it
wants your program to decide whether it should or should not follow
redirects.
So while a browser (or another tool like curl or wget) might
automatically follow a redirect, HTTPAPI requires you to code it.
The simple solution is to write code that checks for the 302. If you
get a 302, then the server has asked you to redirect to another page.
HTTPAPI provides a routine called http_redir_loc() that you can call to
find out where it wants you to redirect to. You can then issue a new
GET request (such as HTTP_url_get()) to go to that new location.
It's not hard.
If you're really looking for something that's less tightly integrated
with your code, you might consider trying out the command-line
interfaces to HTTPAPI that are included in the current beta version.
http://www.scottklement.com/httpapi/beta/
The command-line interfaces (there's one for QShell and one that's a
native CL command) will automatically handle redirects.
Good luck
Shannon Sumner wrote:
> Hello All,
> I'm in the process of converting a PHP curl request to an RPG script
> using HTTPAPI. The RPG script works quite well. The only problem is
> that the script always returns a 302 as the RC. That is the expected
> behavior. The response is always a redirect to another page. In the
> PHP script the programmer accounted for this by using the following
> code:
> if (strstr($resp, 'app_thankyou.aspx'))
> {
> echo "Thank You!";
> } else if (strstr($resp, 'app_unsub.aspx'))
> {
> echo "Unsubscribed";
> }
> else
> {
> echo "Error";
> }
> Is there away I can trap for this using HTTPAPI?
> Thanks,
> Shannon Sumner
>
>
>
> ------------------------------------------------------------------------
>
> -----------------------------------------------------------------------
> This is the FTPAPI mailing list. To unsubscribe, please go to:
> http://www.scottklement.com/mailman/listinfo/ftpapi
> -----------------------------------------------------------------------
-----------------------------------------------------------------------
This is the FTPAPI mailing list. To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------