Search the Community
Showing results for tags 'tidhttp'.
Found 4 results
-
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; } }
-
I save a JSON file on Dropbox, after reading it I don't get it in the correct UTF-8 state as it left, please advise. I am sending Czech characters {"auth":{"text1":"cz_čřšť","text2":"ýáíé","int":10}} I will get {"auth":{"text1":"cz_èø","text2":"ýáíé","int":10}} POST code procedure TForm2.btn_Upload_JsonClick(Sender: TObject); const API_URL = 'https://content.dropboxapi.com/2/files/upload'; var IdHTTP: TIdHTTP; Res : string; Ssl: TIdSSLIOHandlerSocketOpenSSL; Json : string; Req_Json:TStringStream; begin Json := '{"auth":{"text1":"cz_čřšť","text2":"ýáíé","int":10}}'; Req_Json:=TstringStream.Create(Json); Req_Json.Position:=0; IdHTTP := TIdHTTP.Create(nil); try Memo1.Lines.Clear; IdHTTP.HandleRedirects := True; ssl := TIdSSLIOHandlerSocketOpenSSL.Create(); ssl.SSLOptions.Method := sslvTLSv1_2; ssl.SSLOptions.SSLVersions := [sslvTLSv1, sslvTLSv1_1, sslvTLSv1_2]; ssl.SSLOptions.Mode := TidSSLMode.sslmUnassigned; ssl.SSLOptions.VerifyMode := []; ssl.SSLOptions.VerifyDepth := 0; ssl.host := ''; IdHTTP.IOHandler := ssl; IdHTTP.Request.CustomHeaders.Values['Authorization'] := 'Bearer ' + myAccessToken; IdHTTP.Request.CustomHeaders.Values['Dropbox-API-Arg'] := '{ "autorename": false, "mode": "add", "mute": false, "path": "/CUZK/test3.json", "strict_conflict": false }'; IdHTTP.Request.CustomHeaders.Values['Content-Type'] := 'application/octet-stream'; IdHTTP.Request.CharSet:='utf-8'; Memo1.Lines.Add('** IdHTTP.Request.CustomHeaders.Text **'); Memo1.Lines.Add(IdHTTP.Request.CustomHeaders.Text); Memo1.Lines.Add('** ssl.OnStatusInfoEx **'); ssl.OnStatusInfoEx := IdSSLIOHandlerSocketOpenSSL1StatusInfoEx; (**) Res := IdHTTP.Post(API_URL, Req_Json); memo1.Lines.Add('------------------------------------'); Memo1.Lines.Add(Res); finally IdHTTP.Free; Req_Json.Free; end; GET CODE procedure TForm2.btn_Download_File_Click(Sender: TObject); const API_URL = 'https://content.dropboxapi.com/2/files/download'; var Source: TMemoryStream; IdHTTP: TIdHTTP; Res : string; Ssl: TIdSSLIOHandlerSocketOpenSSL; begin IdHTTP := TIdHTTP.Create(nil); try IdHTTP.HandleRedirects := True; ssl := TIdSSLIOHandlerSocketOpenSSL.Create(); ssl.SSLOptions.Method := sslvTLSv1_2; Ssl.SSLOptions.SSLVersions := [sslvTLSv1, sslvTLSv1_1, sslvTLSv1_2]; ssl.SSLOptions.Mode := TidSSLMode.sslmUnassigned; ssl.SSLOptions.VerifyMode := []; ssl.SSLOptions.VerifyDepth := 0; ssl.host := ''; Source := TMemoryStream.Create; IdHTTP.IOHandler := ssl; IdHTTP.Request.CustomHeaders.Values['Authorization'] := 'Bearer ' + myAccessToken; IdHTTP.Request.CustomHeaders.Values['Dropbox-API-Arg'] := '{ "path": "/CUZK/test3.json" }'; IdHTTP.Request.CharSet := 'utf-8'; Res := ansitoutf8(IdHTTP.Get(API_URL)); memo1.Lines.Add('------------------------------------'); Memo1.Lines.Add(Res); finally IdHTTP.Free; Source.Free; end; end;
-
Delphi XE - error connect DROPBOX via Indy TidHTTP (htttps)
polasss posted a topic in Network, Cloud and Web
I'm having trouble connecting to my DROPBOX account via TidHTTP and I don't know what to do anymore. I want to send a simple text file to DROPBOX in the first stage. procedure TForm2.btn1Click(Sender: TObject); const API_URL = 'https://content.dropboxapi.com/2/files/upload'; cFile = 'D:\testfile.txt'; var wAccessToken : string; Source: TFileStream; IdHTTP: TIdHTTP; Res : string; Ssl: TIdSSLIOHandlerSocketOpenSSL; begin wAccessToken := 'muj_token'; IdHTTP := TIdHTTP.Create(nil); try (* ShowMessage('Indy version: ' + IdHTTP.Version); RESULT MESSAGE : INDY 10.5.9.0 *) IdHTTP.HandleRedirects := True; ssl := TIdSSLIOHandlerSocketOpenSSL.Create(); ssl.SSLOptions.Method := sslvTLSv1_2; ssl.SSLOptions.Mode := sslmUnassigned; ssl.SSLOptions.VerifyMode := []; ssl.SSLOptions.VerifyDepth := 0; ssl.host := ''; Source := TFileStream.Create(cFile, fmOpenRead); IdHTTP.IOHandler := ssl; IdHTTP.Request.CustomHeaders.Values['Authorization'] := 'Bearer ' + wAccessToken; IdHTTP.Request.CustomHeaders.Values['Dropbox-API-Arg'] := '{ "autorename": false,"mode": "add","mute": false,"path": "/test.txt","strict_conflict": false}'; IdHTTP.Request.CustomHeaders.Values['Content-Type'] := 'application/octet-stream'; Memo1.Lines.Add(IdHTTP.Request.CustomHeaders.Text); Res := IdHTTP.Post(API_URL, Source); finally IdHTTP.Free; end; But after the POST command I get the error "error: 1409442E:SSL routines: SSL3_READ_BYTES:tlsv 1 alert protocol" - class EIdOSSLUnderlyingCryptoError with message "Error connectin with SSL" http://imgway.cz/m/hneT.jpg I don't know how to proceed, there is a stupid mistake somewhere. I found similar problems on https://stackoverflow.com/questions/1742900/tidhttp-in-indy-10 , https://stackoverflow.com/questions/7762584/post-problems-with-indy-tidhttp and many other forums. Somewhere it says it may be old INDY (which it is), but DROPBOX's probably has the TLS v1.2 required when TIDHTTP enables it ssl.SSLOptions.Method := sslvTLSv1_2 For the Request track, I stuck to the DROBOX.API structure DROPBOX API DOCUMENTATION https://www.dropbox.com/developers/documentation/http/documentation#files-upload Get access token for: ****************************************************** ************** curl -X POST https://content.dropboxapi.com/2/files/upload \ --header "Authorization: Bearer <get access token>" \ --header "Dropbox-API-Arg: {\"autorename\":false,\"mode\":\"add\",\"mute\":false,\"path\":\"/Homework/ math/Matrices.txt\",\"strict_conflict\":false}" \ --header "Content-Type: application/octet-stream" \ --data-binary @local_file.txt ****************************************************** ************** Even more information: Delphi XE3 Indy 10.5.9.0 with the exe I have the Open SSL files libeay32.dll (v. 1.0.2.17) and ssleay32.dll (v. 1.0.2.17) - but that will not be it. if I throw them away the error is the same DROPBOX requires TLS 1.2 from April On some forums they wrote the same error with old Open SSL files, old INDY, sending via TLS which is not supported by the addressee. But I don't feel either way. I downloaded Open SSL from https://github.com/IndySockets/OpenSSL-Binaries file openssl-1.0.2u-x64_86-win64.zip (I don't know if it's good, there are a bunch of them in the table with differences in the name "r", "s", "t", "u", he chose I'm the last one). Thanks for any advice. -
Windows 7 Home 64bit Delphi XE7 Professional update 1 with FireDAC and Mobile add-on Indy version 10.6.1.518 Android version 10, (on smartphone) Android versions 4.4.4, and 4.4.2 (both on tablets) Issue/Problem: When I launch the app on Android, and click on the [Submit] button, the app shuts down when it tries to access the idhttp section here: idHttp1.get(url_address); It works fine under Windows FMX and VCL, just not Android. Can someone please help me resolve this? Thank you. History: Hi. I have been successfully creating small utility apps on my android devices (Galaxy S10+ (android 10) and tablets (android 4.x.x)) for the last 8 years. I've been playing around with a new windows project using API through OMdbAPI (an IMDB knock-off) to get quick movie/tv series info. The API is free for 1000 requests. I love it. It works well. Usage is simple, using the following -> [https://www.omdbapi.com/?t=Contact&apikey={8-dig-key-code}] as it will give back a JSON string (below), then I parse it to get back a two-column detail to visualize the data better. Later I plan to fine-tune it and display only certain info from it. Right now, I am simply debugging it on Windows 7 and Android. {"Title":"Contact","Year":"1997","Rated":"PG","Released":"11 Jul 1997","Runtime":"150 min","Genre":"Drama, Mystery, Sci-Fi","Director":"Robert Zemeckis","Writer":"James V. Hart, Michael Goldenberg, Carl Sagan","Actors":"Jodie Foster, Matthew McConaughey, Tom Skerritt","Plot":"Dr. Ellie Arroway, after years of searching, finds conclusive radio proof of extraterrestrial intelligence, sending plans for a mysterious machine.","Language":"English, Spanish, German, Russian","Country":"United States","Awards":"Nominated for 1 Oscar. 14 wins & 32 nominations total","Poster":"https://m.media-amazon.com/images/M/MV5BYWNkYmFiZjUtYmI3Ni00NzIwLTkxZjktN2ZkMjdhMzlkMDc3XkEyXkFqcGdeQXVyNDk3NzU2MTQ@._V1_SX300.jpg","Ratings":[{"Source":"Internet Movie Database","Value":"7.5/10"},{"Source":"Rotten Tomatoes","Value":"68%"},{"Source":"Metacritic","Value":"62/100"}],"Metascore":"62","imdbRating":"7.5","imdbVotes":"274,457","imdbID":"tt0118884","Type":"movie","DVD":"16 Dec 1997","BoxOffice":"$100,920,329","Production":"N/A","Website":"N/A","Response":"True"}