Help with api / Json

Help with api / Json

Postby wartiaga » Wed Jul 04, 2018 6:07 pm

Hi guys,

How i can send this parameters and capture Json return?

Url: http://www.averbeporto.com.br/websys/php/conn.php


Parameters:

{
"mod": "login",
"comp": 5,
"user": "USUARIO",
"pass": "SENHA",
["dump": [1,2]] // Opcional.
}

Error in return:

{
"success": 1,
"logout": 1
}


Success:

{
"success": 1,
"C": {
"id": "00",
"userName": "USUARIO",
"name": "Usuario",
"email": "usuario@dominio.com",
"portal_groups_id": "00",
"type": "U"
},
"S":[...]
}

Thanks in advance!
wartiaga
 
Posts: 204
Joined: Wed May 25, 2016 1:04 am

Re: Help with api / Json

Postby Lailton » Wed Jul 04, 2018 6:11 pm

Hi,

It is a small example similar. you can adjust to your API :)

Code: Select all  Expand view

#include "fivewin.ch"

function main()

    checkString( "Hellu Worldd" )

    checkString( "Holla Mundu", "es" )

    checkString( "Oli Mundu", "pt-BR" )

return nil

function checkString( cString, cLang )

    local a, aErros
    local hResponse

    hResponse := server( strTolangAPI( cString, cLang ) )

    aErros := hResponse["matches"]

    if hb_isArray( aErros )

        aeval( aErros, {|a| msginfo( hb_dumpvar( a["context"] ) ),xbrowse( a["replacements"] ) } )

    endif

return nil

function strTolangAPI( cString, cLang )

    Default cString := ""
    Default cLang := "en-US"

    cString := "https://languagetool.org/api/v2/check?text="+strtran( cString," ","+" )
    cString += "&language="+cLang
    cString += "&enabledOnly=false"

return cString

function server( cUrl )

    local oObj, oErr, hRet := {=>}

    try
        oObj:=createobject('msxml2.xmlhttp.6.0')
    catch oErr
        try
            oObj:=createobject('msxml2.xmlhttp')
        catch oErr
            try
                oObj:=createobject('microsoft.xmlhttp')
            catch oErr
                oObj:=nil
            end
        end
    end

    if hb_isObject( oObj )

        oObj:open("GET",cUrl,.f.)
        oObj:send()

        while oObj:readyState<>4; hb_idlesleep(1); end

        if oObj:status>=200 .or. oObj:status<=299
            hb_jsonDecode(oObj:responseText,@hRet)
        else
            hRet:={"error"=>{"message"=>oObj:responseText,"status"=>alltrim(str(oObj:status))}}
        end

    endif

return hRet

 
Regards,
Lailton Fernando Mariano
User avatar
Lailton
 
Posts: 149
Joined: Fri Jul 20, 2012 1:49 am
Location: Brazil


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot], JoséQuintas and 51 guests