Page 1 of 1

HTTPRequest() generate multiple requests

Posted: Fri Dec 07, 2018 5:07 pm
by poshu
When used with headers, HTTPRequest makes two requests to the server, here is a PB/SB demo:

SB :

Code: Select all

  Procedure HttpGetEvent(Success, Result$, UserData)
    If Success
      ;Debug Result$
    Else
      Debug "HTTPRequest(): Error"
    EndIf
  EndProcedure

  NewMap Headers$()
  Headers$("x-customheader") = "test"
  Headers$("x-customvalue") = "10"
  
  HTTPRequest(#PB_HTTP_Get, "http://localhost/no/state", "", @HttpGetEvent(), 0, Headers$())
PB :

Code: Select all

  If Not InitCGI()
    End
  EndIf
  
  If Not InitFastCGI(5600)
    End
  EndIf
  
  While WaitFastCGIRequest()
  	Debug "Request! x-customheader value : " + CGIVariable("HTTP_X_CUSTOMHEADER")
    If ReadCGI()
      WriteCGIHeader(#PB_CGI_HeaderContentType, "text/plain", #PB_CGI_LastHeader)
  
      WriteCGIString("meh")
    EndIf
  Wend
The first request has empty value for each headers, and only the first server response is actually sent to the HttpGetEvent callback.

Re: 2.21B : HTTPRequest() generate multiple requests

Posted: Mon Dec 10, 2018 9:24 am
by Dirk Geppert
I guess the first request ist a CORS preflight request..

Re: 2.21B : HTTPRequest() generate multiple requests

Posted: Wed Dec 12, 2018 5:58 pm
by poshu
Possible, is it expected?

It's not a problem anyway, I was just surprised to see two request hitting my server every time.

Re: 2.21B : HTTPRequest() generate multiple requests

Posted: Fri Aug 30, 2019 3:11 pm
by Fred
It's the standard behaviour