drazde 0 Posted October 26, 2020 Hi, I use THttpCli component (ICS v8.61) for downloading files. It works well in many case, but when I try pass a parameter with space (encoding with "+" or "%20") I have the error 400 Bad Request Why? What can I do? PS: if I put the url in a browser, the request is successful text/html; charset=iso-8859-1 => CONSEGNA Attestazione avvenuta pubblicazione avviso selezione infermiere.eml Location = http://192.168.2.221/cbadoc/upload/2019/08/14/CONSEGNA Attestazione avvenuta pubblicazione avviso selezione infermiere.eml URL = http://192.168.2.221/cbadoc/download.php?file=CONSEGNA+Attestazione+avvenuta+pubblicazione+avviso+selezione+infermiere.eml&id=20878&liv1=2019&liv2=08&liv3=14 Document = CONSEGNA Attestazione avvenuta pubblicazione avviso selezione infermiere.eml RequestDone, no error. Status = 400 Request Failed ! StatusCode = 400 ReasonPhrase = Bad Request Share this post Link to post
Angus Robertson 577 Posted October 26, 2020 The server has decided it does not like your parameter encoding, but you don't say you how you do it. Generally, you encode to UTF8 first, then use IcsUrlEncode for each parameter, then combine the parameters. But there are variations on URL encoding, the latest beta has a new strict parameter for Twitter which is very fussy. The better way is to change your application to use TSslHttpRest component, which has RestParams that do all this stuff for you, mostly correctly. . But update to at least V8.64 first, or even the overnight zip, there have been a lot of changes this year. Angus Share this post Link to post
Virgo 18 Posted October 26, 2020 Since it is plain http you can use Wireshark to check, what is different in network request comparing browser and you program. Share this post Link to post
Fr0sT.Brutal 900 Posted October 27, 2020 +1 for comparing to browser. Moreover, you don't even need Wireshark, just the browser's Dev tools with which you even can modify requests before sending. Share this post Link to post
drazde 0 Posted October 27, 2020 I know, this isn't a good solution, but with TDownloadURL component I don't have this problem in this cases.... I use this component only for downloading file that have params with space and all other with THttpCli. I don't want use always TDownloadURL because it have many other problems... Share this post Link to post
Angus Robertson 577 Posted October 27, 2020 THttpCli does not encode any parameters, you added that coding, so if the URL does not work you need to correct your code as I suggested yesterday. Angus Share this post Link to post
drazde 0 Posted October 27, 2020 4 hours ago, Angus Robertson said: THttpCli does not encode any parameters, you added that coding, so if the URL does not work you need to correct your code as I suggested yesterday. Angus I have update ICS component with the latest (v8.65), I use UTF8Encode and then IcsUrlEncode (on the filename parameter the other are merely numbers) but nothing... I remain the better solution is pass the parameters in post (not in get like now), so I think I will talk with my colleague for change it. Thanks for your answers Share this post Link to post
Angus Robertson 577 Posted October 27, 2020 URL encoding for GET and POST is the same, although POST may accept Json or XML instead. Don't like + for space, should always be %20. The + originates from browser form fields with application/x-www-form-urlencoded MIME POST content, and should not be used in URLs or parameters. Angus Share this post Link to post