dan27125 0 Posted January 26 (edited) Indy TIdHTTP->Get UnicodeString trouble Can you teach me how to format an acceptable string to pass to TIdHTTP->Get() ? I'm working with Embarcadero C++Builder 11 trying to learn how to use Indy TIdHTTP->Get(). Attached are two examples. goodClick works but the URL is hard coded. badClick doesnt work. Looks maybe like I'm not properly formatting the URL string passed to TIdHTTP->Get(). The ip address is comming from a classic 8 bit ascii null terminated string like this "192.168.1.123". sprintf(urlAscii, "http://%s//ajax.xml",iniCfg.ethTcp_ip); I need to take the ip address from iniCfg.ethTcp_ip which is an (8 bit asci null terminated string) How can I fix the badClick example ? here is example code... Thanks for your time !! void __fastcall TEthTcpGateway::Button_goodClick(TObject *Sender) { try { // This example works fine String s = "http://192.168.1.123/ajax.xml"; //Use hard coded string UnicodeString url,us; url = "http://192.168.1.123/ajax.xml"; us = IdHTTP1->Get(url); AnsiString as = us; Memo1->Lines->Text = us; } catch (Exception &ex) { out << "Exception " << endl; } } //--------------------------------------------------------------------------- void __fastcall TEthTcpGateway::Button_badClick(TObject *Sender) { extern char ethTcp_ip[64]; // Null terminated 8 bit character buffer "192.168.1.123"; try { // This example does not work. char urlAscii[1000]; // ethTcp_ip has classic 8 bit ascii null terminated string like this "192.168.1.123"; sprintf(urlAscii, "http://%s/ajax.xml",ethTcp_ip); String s = urlAscii; UnicodeString url,us; url = s; // Copy from String us = IdHTTP1->Get(url); AnsiString as = us; out << "Response" << endl << as.c_str() << endl; Memo1->Lines->Text = us; } catch (Exception &ex) { out << "Exception " << endl; } } Edited January 27 by dan27125 TypeO Share this post Link to post
Remy Lebeau 1394 Posted January 27 (edited) 6 hours ago, dan27125 said: Indy TIdHTTP->Get UnicodeString trouble This issue has nothing to do with Unicode. You simply have a logic bug in your code. 6 hours ago, dan27125 said: Can you teach me how to format an acceptable string to pass to TIdHTTP->Get() ? You are already doing it. You just have a mistake in your format string. BTW, you can get rid of the char[] array and use the (s)printf() method of AnsiString/UnicodeString instead, eg: AnsiString url; url.printf("http://%s/ajax.xml", ethTcp_ip); String us = IdHTTP1->Get(url); out << "Response" << endl << AnsiString(us).c_str() << endl; Memo1->Lines->Text = us; Another option, albeit a little heavier-handed, is to use Indy's TIdURI class, eg: #include <IdURI.hpp> #include <memory> std::unique_ptr<TIdURI> idUri(new TIdURI); // or: auto idUri = std::make_unique<TIdURI>(); idUri->Protocol = _D("http"); idUri->Host = ethTcp_ip; idUri->Path = _D("/"); idUri->Document = _D("ajax.xml"); String url = idUri->URI; Quote Attached are two examples. goodClick works but the URL is hard coded. badClick doesnt work. Looks maybe like I'm not properly formatting the URL string passed to TIdHTTP->Get(). Look VERY CAREFULLY at the two URLs you are passing to TIdHTTP::Get(). What do you see that is different between them? In the bad example, there is an extra erroneous '/' character in front of the filename: good: "http://192.168.1.123/ajax.xml" bad: "http://192.168.1.123//ajax.xml" ^ Quote How can I fix the badClick example ? Fix your format string to remove the erroneous '/' character. Quote Also, I'm having finding Indy documenation. Are the Indy documenation links all broken right now? https://www.indyproject.org/documentation/ https://www.indyproject.org/2021/02/10/links-to-old-indy-website-pages-are-currently-broken/ Quote Rad Studio web documenation is also troublesome too, slow or you get errors. https://blogs.embarcadero.com/we-are-experiencing-a-hardware-outage/ https://ideasawakened.com/post/embarcadero-network-issues Quote Right now I'm assuming TIdHTTP->Get takes a UnicodeString string. Yes, but you are not experiencing a Unicode problem, since your URL contains only ASCII characters. Quote Where can I find get PDF or HTML documenantion for Indy that I can download save on my computer ? https://github.com/IndySockets/Indy/wiki/Documentation Edited January 27 by Remy Lebeau Share this post Link to post