ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Scott Klement - YAJL - How do I authenticate before a Post?

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

  • Scott Klement - YAJL - How do I authenticate before a Post?

    Scott, just got introduced to your presentation on the YAJL JSON tool.
    I have been asked to post a JSON file to a URL but I need to be authenticated first.
    Can you point me to the correct example to achieve this?
    Appreciate any help!

  • #2
    Re: Scott Klement - YAJL - How do I authenticate before a Post?

    YAJL just handles conversion from/to JSON. You need HTTPAPI to communicate with the other machine.

    Comment


    • #3
      Re: Scott Klement - YAJL - How do I authenticate before a Post?

      Thanks for the reply Ted. I have HTTPAPI. Project changed on me since my post. All I need to do is post a JSON file to a supplied URL. No security.
      I have tried the http_url_post_raw() and couple others but I am getting a 'HTTP/1.1 400 BAD_REQUEST' error every time.
      All of the GET's seem to work fine. Any example of a simple JSON post?

      Comment


      • #4
        Re: Scott Klement - YAJL - How do I authenticate before a Post?

        YAJL is for formatting/reading JSON data. It has nothing to do with URLs or authentication.

        I think Ted is on the right track here... you need some sort of a tool to access the URL that you mention, and assuming it's an http/https URL, then HTTPAPI is one possible tool. (There are others, but HTTPAPI is my tool for that.) HTTPAPI has routines for HTTP authentication using the Basic, Digest and NTLM schemes. If you need another type of authentication, that might have to be done with another add on of some sort.

        Comment


        • #5
          Re: Scott Klement - YAJL - How do I authenticate before a Post?

          Maybe this can give an idea

          Code:
          // construct a JSON message with YAJL support           
          yajl_genOpen(*on);                                      
            yajl_beginObj();                                      
              yajl_addNum('number':'123456');                     
              yajl_addChar('name':'Rützou');                      
            yajl_endObj();                                        
          yajl_getBuf(jsonAddr:jsonSize);                         
                                                                  
          // Construct a temporary result file name for HTTPAPI   
          tmpFile = '/tmp/tst'+uniqueKey+'.json'; // you need a unique file name                
                                                                  
          // Setup HTTPAPI Url and parms                          
          HTTP_debug(*on);                                        
          HTTP_SetCCSIDs(1208:1208);                              
          HTTP_SetFileCCSID(1208);                                
          url = 'http://127.0.0.1:8080/pextcd2lib/yajl.pgm';      
                                                                  
          // Send HTTPAPI Request                                 
          rc = http_url_post( url                                 
                            : jsonAddr                            
                            : jsonSize              
                            : tmpfile               
                            : HTTP_TIMEOUT          
                            : HTTP_USERAGENT        
                            : 'application/json');  
           //               : 'text/plain');        
                                                    
          // HTTPAPI Error Handling                 
          if rc <> 1;                               
            dsply %char(rc);                        
            dsp = http_error;                       
            dsply  dsp;                             
            *inlr = *on;                            
            return;                                 
          endif;     
                                                      
          // Display HTTPAPI result with qcmd method 
          qcmd('dspf (''' + tmpFile + ''')');

          Comment


          • #6
            Re: Scott Klement - YAJL - How do I authenticate before a Post?

            Thanks for the example. That's what I was looking for.

            Comment

            Working...
            X