[Solved] Tprocess and Curl lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- chrnobel · 2019-07-01 22:41 Hi. I am trying to retrieve some REST data via CURL. The command line CURL sentence is: curl -X GET -H "X-AppSecretToken:demo" -H "X-AgreementGrantToken:demo" -H "Content-Type: application/json" https://restapi.e-conomic.com/products But if I try to do something similar using TProcess, all I get back is an server error, saying it is a bad request. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i AProcess := TProcess.Create(nil);url:='https://restapi.e- conomic.com/products';stoken:='demo';gtoken:='demo';AProcess.Executabl e:='curl';AProcess.Parameters.Add('-X GET ');AProcess.Parameters.Add('-H ');AProcess.Parameters.Add('"X-AppSecretToken:'+stoken+'" ');AProcess.Parameters.Add('-H ');AProcess.Parameters.Add('"X-AgreementGrantToken:'+gtoken+'" ');AProcess.Parameters.Add('-H ');AProcess.Parameters.Add('"Content- Type: application/json" ');AProcess.Parameters.Add(url); AProcess.Options := AProcess.Options + [poWaitOnExit, poUsePipes];AProcess.Execute;AStringList := TStringLi st.Create;AStringList.LoadFromStream(AProcess.Output); writeln(AString List.CommaText);   I have tried to play around using single quotes instead of double quotes, but I makes no change. What have I overlooked? ---------------------------------------------------------------------- lucamar · 2019-07-02 00:53 I don't know whether it's important or not, but shouldn't it be: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i AProcess := TProcess.Create(nil);url:='https://restapi.e- conomic.com/products';stoken:='demo';gtoken:='demo';AProcess.Executabl e:='curl';AProcess.Parameters.Add('-X GET ');AProcess.Parameters.Add('-H "X-AppSecretToken:'+stoken+'" ');AProcess.Parameters.Add('-H "X-AgreementGrantToken:'+gtoken+'" ');AProcess.Parameters.Add('-H "Content-Type: application/json" ');AProcess.Parameters.Add(url); AProcess.Options := AProcess.Options + [poWaitOnExit, poUsePipes];AProcess.Execute;AStringList := TStringLi st.Create;AStringList.LoadFromStream(AProcess.Output); writeln(AString List.CommaText); That is, make sure what is just one parameter gets passed as one parameter. ---------------------------------------------------------------------- chrnobel · 2019-07-02 06:39 Hi lucamar. I have actually also tried that, but the result is the same: Error 400 Bad Request, meaning something is actually send to the server, and the url seems to be right, but the header parameters are wrong. TProcess.Commandline works: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i AProcess.CommandLine:='curl -X GET -H "X-AppSecretToken: demo" -H "X-AgreementGrantToken: demo" '+'-H "Content-Type: application/json" https://restapi.e-conomic.com/products'; However commandline is deprecated, so I dont think that is the right path to follow. ---------------------------------------------------------------------- Thaddy · 2019-07-02 06:46 Why do you do not use libcurl directly? ---------------------------------------------------------------------- marcov · 2019-07-02 08:06 The initial, but then without any quoting. So remove " and trailing spaces Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i AProcess.Ex ecutable:='curl';AProcess.Parameters.Add('- X');AProcess.Parameters.Add('GET');AProcess.Parameters.Add('- H');AProcess.Parameters.Add('X- AppSecretToken:'+stoken);AProcess.Parameters.Add('- H);AProcess.Parameters.Add('X- AgreementGrantToken:'+gtoken);AProcess.Parameters.Add('- H');AProcess.Parameters.Add('Content-Type: application/json');AProcess.Parameters.Add(url);  Url should also be free of quotes. Keep in mind that quoting is something from shells. Here you execute over API directly, without spawning an additional shell, and you give all arguments separated -> quoting is redundant. ---------------------------------------------------------------------- chrnobel · 2019-07-02 08:08 Quote from: Thaddy on July 02, 2019, 08:46:40 amWhy do you do not use libcurl directly? I have tried to search, but the documentation is close to 100% absent, so where can I find a working example, and some documentation? ---------------------------------------------------------------------- chrnobel · 2019-07-02 08:16 Quote from: marcov on July 02, 2019, 10:06:03 amThe initial, but then without any quoting. So remove " and trailing spaces Url should also be free of quotes. I guess you mean: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i url:='https ://restapi.e- conomic.com/products';stoken:='demo';gtoken:='demo';AProcess.Executabl e:='curl';AProcess.Parameters.Add('-X GET');AProcess.Parameters.Add('- H');AProcess.Parameters.Add('X- AppSecretToken:'+stoken);AProcess.Parameters.Add('- H');AProcess.Parameters.Add('X- AgreementGrantToken:'+gtoken);AProcess.Parameters.Add('- H');AProcess.Parameters.Add('Content-Type: application/json');AProcess.Parameters.Add(url); Makes no difference. ---------------------------------------------------------------------- marcov · 2019-07-02 08:30 -X and GET also separate adds, sorry read over that. I updated my answer. ---------------------------------------------------------------------- chrnobel · 2019-07-02 08:45 Quote from: marcov on July 02, 2019, 10:30:30 am-X and GET also separate adds, sorry read over that. I updated my answer. Thanks marcov, that did the trick.