Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Calling a webapi with parameters
Message
 
To
05/03/2018 08:12:11
General information
Forum:
Visual FoxPro
Category:
Web Services
Miscellaneous
Thread ID:
01658531
Message ID:
01658535
Views:
89
>Good day all, in my current project I need to call a webapi using GET to obtain a json with specific information, I'm already opening the url and its responding like I'm not authenticated, I don't know how to add in the header call the parameters, The example I have for it is like the following:
>The Authorization: bearer -> is followed by a long token string that I already have.
>
>curl -X GET --header 'Accept: application/json' --header 'Authorization: bearer eyJ0..very..long..token..qg' 'https://api-xxinvoicing-co-.com/api/xxnasw/companies'
>
>I'm doing this:
>
>
>    local cKey, cdom
>    cKey="dd...very..long..token"
>    cdom="https://api-xxinvoicing-co-.com/api/xxnasw/companies"
>    LOCAL loXMLHTTP as "MSXML2.XMLHTTP" 
>    loXmlHttp = CREATEOBJECT("MSXML2.XMLHTTP") 
>
>    WITH loXmlHttp 
>
>        .setRequestHeader("Accept", "application/json") &&&getting error here
>        .setRequestHeader("Authorization", "bearer") &&&getting error here
>        .setRequestHeader("bearer", ckey) &&&getting error here
>        .open("GET", cdom, .F.) &&no error
>
>        .Send()  &&no error
>ENDWITH 
>
>MESSAGEBOX(loXmlHttp.responseText,0,"responsetext") &&message not authenticated
>
>
>
>Please let me know how to add the token to the header to be recognized as already authenticated. T.I.A.


Try this format, normally the Key is part of your first request, not done in two separate statements. (This is a VBA example)
oHttp.SetRequestHeader "Authorization", "Basic " + _Base64Encode(authUser + ":" + authPass)
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform