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

Re: [Ftpapi] I'm obviously missing something ...



Got it - thanks.



> On May 4, 2020, at 5:27 PM, Scott Klement <sk@xxxxxxxxxxxxxxxx> wrote:
> 
> Hi Jon,
> 
> You would need to specify the content-type when sending data, which is normally done with a POST or PUT request.
> 
> Simply specify the type 'application/json' (without preceding it with "content-type:") in the appropriate parameter to http_req, http_string, http_stmf, http_post, etc...  then it'll be taken care of for you.
> 
> -SK
> 
> 
> On 5/4/2020 4:19 PM, Jon Paris wrote:
>> OK - thanks.
>> 
>> That explains why the suggestion Charles made on WEB400 to add  http_setAuth(HTTP_AUTH_NONE:'':''); had no impact.
>> 
>> Would I ever need to specify content-type?
>> 
>> 
>> Jon
>> 
>>> On May 4, 2020, at 5:06 PM, Scott Klement <sk@xxxxxxxxxxxxxxxx> wrote:
>>> 
>>> Hi Jon,
>>> 
>>> The way you're sending the content-type will work fine with a GET call, because HTTPAPI doesn't add a content-type with GET. However, if you use the same 'addSpecialHeaders' routine with a POST request, it will list the content-type twice -- once from HTTPAPI, and a second time from your code.   Please consider using HTTPAPI's mechanism for setting the content-type rather than doing it yourself to avoid this conflict.
>>> 
>>> I haven't gotten around to checking WEB400 yet, I'll check that out now.
>>> 
>>> -SK
>>> 
>>> On 5/4/2020 4:01 PM, Jon Paris wrote:
>>>> Thanks Scott,
>>>> 
>>>> I'll look at those options.
>>>> 
>>>> I was hoping someone would respond since I have resolved the problem but had no email to reply to!
>>>> 
>>>> In the end I had missed something - I had failed to notice just how huge the JWT authorization code was and defined the field too small - in the log I had done a check on what was shown but didn't check far enough down the string to notice the end had dropped off.
>>>> 
>>>> As to the content type - the API specification (and all their code samples) call for it so I left it in place.  In the case of all of the POST APIs this will be required so I guess for simplicity they just leave it in all the time.
>>>> 
>>>> Thanks for your help.
>>>> 
>>>> 
>>>>> On May 4, 2020, at 4:48 PM, Scott Klement <sk@xxxxxxxxxxxxxxxx> wrote:
>>>>> 
>>>>> Hi Jon,
>>>>> 
>>>>> I don't know why you are getting the '401' error?  Possibly there's a problem with the Bearer token you're using?  When a login fails, the HTTP protocol typically will just re-send the 401 error.  So if you give a bad userid/password, it'll simply say '401, I need a userid/password' or if you give a bad bearer token, same thing, etc.
>>>>> 
>>>>> Its not clear why you are adding a 'content-type' here. Content-type is meant to tell the receiving system what sort of data is being sent.  In this example, you are doing a GET request, so it is not sending any sort of data (aside from the URL itself, but content-type does not relate to the URL...)
>>>>> 
>>>>> I'd also recommend switching to use the newer APIs such as http_string, http_stmf or http_req rather than the old stuff like http_get.  It really shouldn't matter for what you're doing, but as it gets more sophisticated, you'll find the old routines like http_get are difficult to use.
>>>>> 
>>>>> -SK
>>>>> 
>>>>> 
>>>>> On 5/4/2020 12:00 PM, Jon Paris wrote:
>>>>>> Cross-posted to HTTPAPI and WEB400
>>>>>> 
>>>>>> I just coded up a basic Zoom API request - this is the basic HTTPAPI code:
>>>>>> 
>>>>>>        url = 'https://api.zoom.us/v2/webinars/' +
>>>>>>              %EditC(webinarId: 'X') +
>>>>>>              '/tracking_sources';
>>>>>> 
>>>>>>        headerVars.contentType   = 'application/json';
>>>>>> 
>>>>>>        headerVars.authorization = 'Bearer mySecrtetCodeGoesHere';
>>>>>> 
>>>>>>        http_xproc( HTTP_POINT_ADDL_HEADER
>>>>>>                  : %paddr(addSpecialHeaders)
>>>>>>                  : %addr(headerVars) );
>>>>>> 
>>>>>>        rc = http_get( url: '/tmp/result.txt' );
>>>>>>        if rc <> 1;
>>>>>>           http_crash();
>>>>>>        endif;
>>>>>> 
>>>>>> 
>>>>>>        Dcl-Proc addSpecialHeaders;
>>>>>>        Dcl-Pi *N;
>>>>>>          headersToAdd    Varchar(32767);
>>>>>>          vars            likeds(headerVars) const;
>>>>>>        End-Pi;
>>>>>> 
>>>>>>        Dcl-C CRLF x'0d25';
>>>>>> 
>>>>>>        headersToAdd = 'content-type: ' + vars.contentType + CRLF
>>>>>>                     + 'authorization: ' + vars.authorization + CRLF;
>>>>>>        End-Proc;
>>>>>> 
>>>>>> 
>>>>>> This gives me a "401 - This page requires a user-id & password" error
>>>>>> 
>>>>>> If I copy/paste the credentials and URL into Insomnia and test it - it works.  The user Id stuff is in the "secret key" bit.
>>>>>> 
>>>>>> Since I copied and pasted this stuff into insomnia from the RPG stuff I can only assume I missed a step somewhere. But where?
>>>>>> 
>>>>>> 
>>>>>> Jon Paris
>>>>> -- 
>>>>> _______________________________________________
>>>>> Ftpapi mailing list
>>>>> Ftpapi@xxxxxxxxxxxxxxxxxxxxxx
>>>>> http://scottklement.com/mailman/listinfo/ftpapi
>>> -- 
>>> _______________________________________________
>>> Ftpapi mailing list
>>> Ftpapi@xxxxxxxxxxxxxxxxxxxxxx
>>> http://scottklement.com/mailman/listinfo/ftpapi
> -- 
> _______________________________________________
> Ftpapi mailing list
> Ftpapi@xxxxxxxxxxxxxxxxxxxxxx
> http://scottklement.com/mailman/listinfo/ftpapi

-- 
_______________________________________________
Ftpapi mailing list
Ftpapi@xxxxxxxxxxxxxxxxxxxxxx
http://scottklement.com/mailman/listinfo/ftpapi