HMG Tutorials & Tips

Exclusive forum for HMG, a Free / Open Source xBase WIN32/64 Bits / GUI Development System
  1. Thank you very much Edward.

    Statistics: Posted by zolysoftsolutions — Fri Mar 09, 2018 6:18 pm

  2. Hi Zoli.
    In most cases, you send a JSON string with HTTP POST.
    Some APIs may require setting the appropriate HTTP header.

    Here is an example of simple communication with the Mandrill API:


    /* hb_json* samples:!topic/harbour-users/jl5N5DCNgxg!topic/harbour-users/nvLkUwlS9xw*/#include ""Function Main()Mandrill_()Return Nil****************************************************************************************Function Mandrill_()Local cURL, cApiUrl := ""Local cAPIKey:="SomeAPIKey"Local cPOSTdataLOCAL h, oMandrill, hResp//InitBEGIN SEQUENCE WITH {|o| break(o)}oMandrill := Win_OleCreateObject( "MSXML2.ServerXMLHTTP" )RECOVER     MsgStop( "Microsoft XML Core Services (MSXML) 6.0 is not installed."+CRLF+;          "Download and install MSXML 6.0 from"+CRLF+;          "before continuing.")     oMandrill:=""END SEQUENCEIF EMPTY(oMandrill)MsgStop("Error while init.")RETURN ENDIF//ping//'Prepare for Ping')cURL := cApiUrl + "/users/ping2.json"h := { => }    h [ "key" ] := cAPIKeycPOSTdata := hb_jsonEncode( h , .T. )//send as JSONcResp := SendMandrill( cUrl, cPOSTdata, oMandrill )IF cResp = "!ERROR!"MsgStop( cResp )/* Report any errors */ELSEMsgInfo( cResp , 'Response from server as JSON string')hResp := hb_jsonDecode( cResp )MsgDebug( hResp )cStatus     := hb_HGet( hResp  , "status" )nCode       := hb_HGet( hResp  , "code" )cName       := hb_HGet( hResp  , "name" )cMessage    := hb_HGet( hResp  , "message" )MsgDebug( cStatus , nCode , cName , cMessage )ENDIF//CloseoMandrill:Abort()RETURN *****************************************************************************************Function SendMandrill (cUrl, cPOSTdata, oMandrill)Local cReturnBEGIN SEQUENCE WITH {|o| break(o)}oMandrill:Open( "POST", cUrl, .F. )oMandrill:setRequestHeader("User-Agent", "Mandrill-Curl/1.0")oMandrill:Send( cPOSTdata )cReturn := oMandrill:ResponseBody()RECOVER USING oErrcReturn := "!ERROR!" + CRLF + oErr:Description END SEQUENCE RETURN cReturn*****************************************************************************************


    Statistics: Posted by edk — Fri Mar 09, 2018 5:59 pm

  3. Hi my friends,

    I try to communicate between my local mysql database and a web application.
    How can I send JSON to api and how can I recieve JSON from api?
    Thank you in advance.

    Zoli B.

    Statistics: Posted by zolysoftsolutions — Fri Mar 09, 2018 4:02 pm

  4. uauuu... primeiro material que encontro com dicas para iniciantes como eu e tantos outros!

    Statistics: Posted by MICROVOLUTION — Mon Feb 19, 2018 11:44 pm

  5. try:


    ON KEY ALT+ADD ACTION Form_1.Grid_1.CheckBoxAllItems := .T.//ALT with Num+ :=> Check AllON KEY ALT+SUBTRACT ACTION Form_1.Grid_1.CheckBoxAllItems := .F.//ALT with Num- :=> UnCheck AllON KEY ALT+MULTIPLY ACTION ReverseCheck()//ALT with Num* :=> Reverse Check/UnCheck All@ 450, 155 BUTTON Button_1 CAPTION "Check All" ACTION Form_1.Grid_1.CheckBoxAllItems := .T.@ 450, 355 BUTTON Button_2 CAPTION "UnCheck All" ACTION Form_1.Grid_1.CheckBoxAllItems := .F.@ 450, 555 BUTTON Button_3 CAPTION "Reverse Check" ACTION ReverseCheck()****************************FUNCTION ReverseCheck()Local iFOR i = 1 TO Form_1.Grid_1.ItemCountForm_1.Grid_1.CheckBoxItem ( i ) := ! Form_1.Grid_1.CheckBoxItem ( i )NEXT iRETURN

    Statistics: Posted by edk — Thu Feb 08, 2018 8:27 am