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 there are three bytes of strange characters that precede the desired data. The problem occurs with a given URL and another not.
I’m using examples from Hbtip that come with Harbour 3.2, to try to consume a REST API developed in PHP. The solution I found for the problem was to delete these three initial bytes, invoking the substr() function. But, I would like to better understand the cause. Perhaps, I am not knowing how to use the method correctly. It may also be that the problem is in the API.
Sample snippet of 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
Maybe it’s the GOOD. But in theory the JSON format receives ASCII strings with special character index escapes in the UTF-16 table. If so, the problem is in the API provider that shouldn’t have put it in the beginning of conversation
– Jefferson Quesado
It’s GOOD, really. The PHP page that responds to the single URL that is returning these strange characters was formatted with UTF-8 GOOD. I saved as UTF-8 without GOOD and solved the problem. Thank you!
– Luiz Dataprol
I sincerely suggest staying away from Hbtip in production. I will "borrow" the words of Viktor Szakats: Due to the excessive amount of problem Reports and long known problems and due to the non-trivial Nature of internet protocols, this Fork strongly Recommends to avoid using this library in Anything Production or in Fact Anything more Serious than simple test code for Educational purposes (...) Even if Something Happens to work in some specific scenario, it’s highly likely it’s not a stable Solution, nor is it Secure - And in fact that’s right, Hbtip is practically "tied with wire"
– Bacco
I’m aware of Viktor Szakats' warning. But in my experiments, using HBTIP, so far, it has behaved well, save one exception, and I have found no quick and easy alternative to start using. In this recent case, in particular, the problem was in the PHP page of the API I built or in formatting the files written in xbase. The PHP page was saved in UTF-8 format with BOM and returned the three byte order mark characters ("byte order mark") or perhaps something similar. xbase files were saved with UTF-8 without BOM and working with character map in ASCII format
– Luiz Dataprol
https://i.stack.Imgur.com/Luo3a.jpg
– Maniero
@Luizdataprol highlight for the finale that I did not stick here for nothing kkk: "Even if Something Happens to work in some specific scenario, it’s highly likely it’s not a stable Solution, nor is it Secure". Note that it is only a recommendation, if you want to use it is already with you in the package. I only mentioned it to try to keep you from building something on top of it so you’ll regret it and have to change it anyway. Get ready to find many exceptions. If you’re going to work with email one day, don’t even talk. What HBTIP can be useful to you is to look at the source and take advantage of parts that matter in your own code.
– Bacco
@Bacco, I have read reports, in discussion forums xbase programming, regarding difficulties and problems of using HBTIP. I do not intend to use it in production, knowing that it does not work well. But I was curious to test the resources and know, in practice, what works well and what does not and what its motives. As you suggested, really, it is possible to take advantage of some parts of it at first.
– Luiz Dataprol
So far, HTTP transactions, with my API, using HBTIP, for example, without SSL, have worked. The problem I found, in this, was trying to send JSON strings of data, without having to insert in the URL, by the GET method. It does not accept. But, as it works, in the same way, by the OPEN method, I was able to get around. For my studies of the feasibility of use, in parallel, I use Postman and compare the behaviors.
– Luiz Dataprol
I didn’t get it right. GET is always by URL (so much so that usually GET doesn’t have Body). Any lib that sends data via GET at the end will put the data in the path anyway (even if in lib you use a separate URL function)
– Bacco
Yeah. That’s what I learned, too. But since Postman allows using the "body" area to enter the JSON data, in order to send by GET, I thought there was some way to send by body or that, as you said yourself, it sent by URL and that HBTIP also do this.
– Luiz Dataprol