0

When I call the Read method, right after an Open of the TIPClientHttp class, I get a JSON string from a PHP page. However, I noticed that three bytes of strange characters that precede the desired data occur, along. This happens with one URL and with another no.

I'm using examples of HBTIP, of the xBase language of the Project Harbour 3.2, to try to consume a REST API developed in PHP. The solution I found for the problem was to suppress these initial three bytes by invoking the Substr function. But I'd like to better understand the cause. Maybe I don't know how to use the method correctly. It may also be that the problem is in the API.

Sample excerpt from my code where the problem happens:

    oHTTP := TIPClientHttp():new( "http://localhost/api/index.php/clients" ) 
    oHTTP:setCookie(cSessaoAtiva)
    oHTTP:hFields := hAuthBearer
    if oHTTP:Open()
        cJSON := oHttp:read()
        cJSON := substr(cJSON,4) // Remove 3 bytes estranhos que aparecem 
                                // no início da string, quando lida logo
                                // depois do método Open().
        cSessaoAtiva := oHTTP:getcookies()
    else
        ? "Etapa #1 Error:", "oHTTP:Open()", oHTTP:lastErrorMessage()
    endif

0 Answers0