ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

HTTPAPI - user and password embedded in link ok?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • HTTPAPI - user and password embedded in link ok?

    I use HTTPAPI to retrieve other csv files. Now I've got one that should be simple, but I'm getting the following:
    Code:
    HTTPAPI Ver 1.32 released 2016-02-10
    NTLM Ver 1.4.0 released 2014-12-22
    OS/400 Ver V7R2M0
    
    New iconv() objects set, PostRem=819. PostLoc=0. ProtRem=819. ProtLoc=0
    http_url_get(): entered
    http_persist_open(): entered
    http_long_ParseURL(): entered
    DNS resolver retrans: 1
    DNS resolver retry  : 2
    DNS resolver options: x'00000136'
    DNS default domain: drj.la
    DNS server found: 10.100.10.21
    DNS server found: 10.100.10.22
    DNS server found: 4.2.2.2
    SetError() #2: Host name look up failed.
    This is the URL (with my user and password removed):
    Code:
    url = 'http://tables.zip2tax.com?usr=username&pwd=password&id=1';
    I can ping the target domain successfully from the IBM i command line. I can use the whole link and successfully download the csv file from a browser. But when I try to do it from within my RPG using HTTPAPI, it gives me the above error.

    In this particular case, the difference from other files that I retrieve similarly from other sites, is that the user name and password is embedded in the URL. And the password they gave me has an @ sign in it. Is that a problem and could it be generating the error I'm getting?

  • #2
    It is possible that HTTPAPI is getting confused by the @ character... try encoding it.

    Comment


    • #3
      Ok, I got my password changed so it doesn't contain the @ sign, and have gotten it to work, sort of...

      Now I get the message "HTTP/1.1 302 Object Moved". So the target site is redirecting me. And that makes sense, because that last part of the URL is "&id=1" which tells it to grab the latest tax file. That redirects it to a URL for the latest tax file. So instead of getting the file downloaded to my IFS, I get a file with a message that the tax file I'm trying to get is in a different location. So then to test it, I took that longer URL from the message and put that in my RPG program and got the tax file down successfully.

      QUESTION: How can I get HTTPAPI to follow that redirect to the new URL and grab the file I want, rather than telling me that the file has been moved to the new URL? That way my RPG can always use the URL with the "&id=1" and always get the latest tax file without me having to update the URL to the specific one each time.

      Comment


      • #4
        Got it working! Just had to look for the 302 response and use http_redir_loc(), as shown below:

        Code:
        if rc <> 1;                    
          If rc = 302;                 
            URL = http_redir_loc();    
            rc = http_url_get(URL:IFS);
          Else;                        
            http_crash();              
          Endif;                       
        endif;
        Works great, thanks!

        Comment


        • #5
          So... are you saying that encoding the password didn't work, and you had to get a password without the @ symbol? That doesn't sound right...

          Comment


          • #6
            Sorry, I took the easy way out and just asked for a different password. The one I had was randomly generated and annoying to look up each time I wanted to access their site manually anyway, so I requested one that I specified myself (and it doesn't have the @-sign in it).

            Also, I tried a couple variations of the URL with regard to a slash before the question mark and without, because it wasn't completely clear to me if it should have it or not before the ?usr=username. I would have thought the slash should not be there, but it does seem to want it. So my URL is now:
            Code:
            url = 'http://tables.zip2tax.com/?usr=username&pwd=password&id=1';
            And now everything works. :-)

            Comment

            Working...
            X