HTTPRequest() generate multiple requests

Just starting out? Need help? Post your questions and find answers here.
poshu
Posts: 96
Joined: Mon Feb 24, 2014 11:46 pm

HTTPRequest() generate multiple requests

Post 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.
Dirk Geppert
Posts: 282
Joined: Fri Sep 22, 2017 7:02 am

Re: 2.21B : HTTPRequest() generate multiple requests

Post by Dirk Geppert »

I guess the first request ist a CORS preflight request..
poshu
Posts: 96
Joined: Mon Feb 24, 2014 11:46 pm

Re: 2.21B : HTTPRequest() generate multiple requests

Post 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.
Fred
Site Admin
Posts: 1506
Joined: Mon Feb 24, 2014 10:51 am

Re: 2.21B : HTTPRequest() generate multiple requests

Post by Fred »

It's the standard behaviour
Post Reply