Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Create HTTP Request object
Message
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
01645753
Message ID:
01645881
Views:
46
Hi Dmitri,

this sounds like a REST-Service like I have used in my application so here a two methods of a class I have written. It uses wwipstuff, but the newer westwind client tools will do the same.

This is as method using POST to get a token.
FUNCTION login 
lRueck = .F.
cToken = ""
IF RIGHT(this.cUrl,1) <> "/"
   this.cURL = this.cUrl + "/"
Endif
cLoginURL = this.cURL + "login"
cContent = "{ " + Chr(34) + "username" + Chr(34) + " : " + Chr(34) + this.cUser + Chr(34) + ", " + Chr(34) + "password" + Chr(34) + " : " + Chr(34) + this.cPasswort + Chr(34) + "}"
this.oHTTP = CREATEOBJECT("wwhttp")
this.oHTTP.AddPostKey(cContent)
this.oHTTP.cExtraHeaders = "content-type:application/json" + CHR(13) + CHR(10)
lcHTML = this.oHTTP.HTTPGet(cLoginURL)
IF this.oHTTP.cResultcode = "200"
   lRueck = .T.
   this.cToken = lcHTML
ELSE
   this.cErrortext = this.oHTTP.cErrorMsg
Endif
RETURN (lRueck)
ENDFUNC
Then, for further calls it uses the token for authorisation:
FUNCTION donursuche
LPARAMETERS cSuche
   lRueck = .F.
   this.oHTTP.cExtraHeaders = "accept:application/json" + CHR(13) + CHR(10) ;
     + "Authorization:Bearer" + this.cToken  + CHR(13) + CHR(10)
   cSuchurl = this.cUrl + "products?search=" + cSuche + "&size=100" + "&sourde=VLB"
   cResult = this.oHTTP.HTTPGet(cSuchURL) 
   IF this.oHTTP.cResultcode = "200"
      lRueck = .T.
      IF LEN(cResult) > 0
         this.cJson = cResult
      Else
         this.cErrortext = "Keine Antwort erhalten"
      Endif
   ELSE
      this.cErrortext = this.oHTTP.cErrorMsg
   Endif
   RETURN (lRueck)    
ENDFUNC
Have a look at setting the Extraheaders-Property.

Best regards

Thomas
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform