Problem with TResponse.SendRedirect lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- egsuh · 2024-10-23 11:17 In my webserver program, AResponse.SendRedirect does not always work.  The target page is static page. The error message (from IIS) says, QuoteHTTP Error 405.0 - Method Not Allowed Page cannot be displayed as wrong method (HTTP verb) is being used. nginx says the same error. The static page itself is displayed without any problem. And SendRedirect is also done correctly when I directly put it in the ActionRequest --- only through GET method.  It semms that after the web server has received something via POST method, then SendRedirect does not work. What should I check, and what could be solutions? ---------------------------------------------------------------------- rvk · 2024-10-23 11:31 I'm not sure what the problem is (you don't show much code). But TResponse.SendRedirect itself doesn't do much. It just sets the Location header to TargetURL and Code/CodeText to 307 or 302. That is send back to the client. What the client does with it... is up to the client. If the code is redirect/moved... maybe the client wants to do the POST to that new URL. Can your redirected URL (static page) handle POST ?? You could try to do a post to it via curl, just post some dummy data to that page. Next... what is actually the method you receive at that IIS and nginx server when you receive that error. (should be in the logs) ---------------------------------------------------------------------- egsuh · 2024-10-23 13:28 This is rather funny...  I made a simple example. You may try this on: http://www.alphaq.biz/htmls/p121_002.htm Code: Text  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 프로그램 테스트   
Your name:

 
Within Post method form : 


Within Get method form: 
AQ02cb/e/test has following code: 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 procedure TwmAQe.TestRequest(Sender: TObject; ARequest: TRequest;   AResponse: TResponse; var Handled: Boolean);begin   Aresponse.SendRedirect(Format('http://%s/htmls/p121_002.htm', [ARequest.Host]));   Handled:= True;end;  When you press the second button, you'll see the same page again. But when you press the first button, you'll get error message. BTW, button's onclick link seems to do nothing in this case. ---------------------------------------------------------------------- rvk · 2024-10-23 13:46 The page http://www.alphaq.biz/htmls/p121_002.htm doesn't allow POST. According to the headers, only GET, HEAD, OPTIONS, TRACE is allowed. So if you do a POST to http://www.alphaq.biz/betas/aq02cb/e/test and that page gives a redirect... the browsers follows this up with a POST to that redirected URL. Who is serving the page http://www.alphaq.biz/htmls/p121_002.htm and why is a POST to that page set as 'not allowed'? QuoteHTTP/1.1 405 Method Not Allowed Allow: GET, HEAD, OPTIONS, TRACE Content-Type: text/html Server: Microsoft-IIS/10.0 X-Powered-By: ASP.NET Date: Wed, 23 Oct 2024 13:42:20 GMT Content-Length: 1307 So dive into that Microsoft-IIS and allow a POST to that page. And if this is really not a page where you can POST to... then you SHOULDN'T use the 307 redirect. Quote15.4.8. 307 Temporary Redirect The 307 (Temporary Redirect) status code indicates that the target resource resides temporarily under a different URI and the user agent MUST NOT change the request method if it performs an automatic redirection to that URI. Since the redirection can change over time, the client ought to continue using the original target URI for future requests. The server SHOULD generate a Location header field in the response containing a URI reference for the different URI. The user agent MAY use the Location field value for automatic redirection. The server's response content usually contains a short hypertext note with a hyperlink to the different URI(s).https://www.rfc- editor.org/rfc/rfc9110.html#name-307-temporary-redirect ---------------------------------------------------------------------- egsuh · 2024-10-24 01:17 I gave up looking into IIS and nginx. Instead, I let my webserver program handle the file. 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 procedure TwmAQe.TestRequest(Sender: TObject; ARequest: TRequest;   AResponse: TResponse; var Handled: Boolean);begin   AResponse.Content := Actions.ActionByName('Test').Template.GetContent;   Handled:= True;end; or     AResponse.Contents.LoadFromFile(Actions.ActionByName('Test').Templ ate.Filename; works as well. But are these the best solution?  I assigned the filename to the Action's Template's filename. Then should it be automatically loaded simply by AResponse.SendRespond; ? ---------------------------------------------------------------------- rvk · 2024-10-24 08:41 Quote from: egsuh on October 24, 2024, 03:17:01 amI gave up looking into IIS and nginx. Instead, I let my webserver program handle the file. Did you read the redirection-3xx section?  You could have just given a 302 'Found' back to the client after which the client would do a GET to that page. The 307 is defined as redirect that the client POST will keep POST, but 301 and 302 will change to GET. So with a 302 the client would have done a GET to that page (which was allowed). https://www.rfc-editor.org/rfc/rfc9110.html#name-redirection-3xx Quote from: egsuh on October 24, 2024, 03:17:01 amI assigned the filename to the Action's Template's filename. Then should it be automatically loaded simply by AResponse.SendRespond; ? I'm not familiar with Action's templates... but I don't see TResponse.SendResponse doing anything automatically. (SendResponse is for Delphi compatibility and it just calls TResponse.SendContent, which just sends the Content)