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

HTTPRequest() generate multiple requests

by poshu Fri Dec 07, 2018 5:07 pm

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: 122
Joined: Fri Sep 22, 2017 7:02 am

Re: 2.21B : HTTPRequest() generate multiple requests

by Dirk Geppert Mon Dec 10, 2018 9:24 am

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

Re: 2.21B : HTTPRequest() generate multiple requests

by poshu Wed Dec 12, 2018 5:58 pm

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: 1161
Joined: Mon Feb 24, 2014 10:51 am

Re: 2.21B : HTTPRequest() generate multiple requests

by Fred Fri Aug 30, 2019 3:11 pm

It's the standard behaviour
Return to Coding Questions

Who is online

Users browsing this forum: No registered users and 2 guests