[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

HTTP_POST request - microsoft translator web service



   Hi, I'm new of the use of http API.

   I have successfully tried to use it to send SOAP request to check
   European VAT code, so I'm trying to use the Microsoft translator api
   ([1]http://api.microsofttranslator.com)


   With the help of SoapUI I get the soap envelope and body, but I have a
   problem with the "access token" request.


   I've done all the subscription requested by Microsoft and obtain
   CLIENT_ID and CLIENT_SECRET as in
   [2]http://msdn.microsoft.com/en-us/library/hh454950.aspx .

   So I'm trying to do the HTML POST request but I receive always  RC=-1


   Can someone tell me where is the error?

   Thanks



   My code is:




   H DFTACTGRP(*NO) BNDDIR('LIBHTTP/HTTPAPI')


    /copy libhttp/qrpglesrc,httpapi_h


   D Enc1            s                   like(HTTP_URL_ENCODER)


   D url             s          32767A   varying


   D data            s          32767A   varying

   D rc              s             10I 0

   D msg             s             50A


   D CLIENTID        s              8A

   D CLIENTSECRET    s             44a

   D SCOPE           s             34a

   D GRANTTYPE       s             18a


   D Incoming        PR

   D   UserData                      *

   D   depth                       10I 0 value

   D   name                      1024A   varying const

   D   path                     24576A   varying const

   D   value                    32767A   varying const

   D   attrs                         *   dim(32767)

   D                                     const options(*varsize)


   d risposta        ds                  qualified

   d   access_token                50A

   d   token_type                  50A

   d   expires_in                  10A

   d   scope                        5A


    /free


       CLIENTID = 'INFORDUE';

       CLIENTSECRET = 'MY_Client_secret_windows_azure_marketplace_x';

       SCOPE = 'http://api.microsofttranslator.com';

       GRANTTYPE = 'client_credentials';


       Enc1 = http_url_encoder_new();

       http_url_encoder_addvar_s(Enc1 : 'client_id'     : CLIENTID     );

       http_url_encoder_addvar_s(Enc1 : 'client_secret' : CLIENTSECRET );


       url = 'https://datamarket.accesscontrol.windows.net/v2/OAuth2-13';

       data = http_url_encoder_getstr(Enc1) +

             '&scope=' + scope + '&granttype=' + GRANTTYPE;


       rc=http_url_post_raw(%trim(url)

                           :%addr(data)

                           : %len(%trimr(data))

                           : 1

                           : %paddr('INCOMING')

                           : HTTP_TIMEOUT

                           : HTTP_USERAGENT

                           : 'application/x-www-form-urlencoded');


       if     rc <> 1;

            msg = http_error;

       endif;


       *inlr =
   *on;



    /end-free

    *=====================================================================
   =========

   P Incoming
   B

   D Incoming
   PI

   D   UserData
   *

   D   depth                       10I 0
   value

   D   name                      1024A   varying
   const

   D   path                     24576A   varying
   const

   D   value                    32767A   varying
   const

   D   attrs                         *
   dim(32767)

   D                                     const
   options(*varsize)



    /free

         select;

         when name =
   'access_token';

           risposta.access_token = value;

         when name =
   'token_type';

           risposta.token_type =
   value;

           risposta.token_type = value;

         when name = 'expires_in';

           risposta.expires_in = value;

         when name = 'scope';

           risposta.scope = value;

         endsl;

    /end-free

   P                 E

References

   1. http://api.microsofttranslator.com/
   2. http://msdn.microsoft.com/en-us/library/hh454950.aspx
-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------