HTTPRrequest doesn't work on android.

Got an idea for enhancing SpiderBasic? New command(s) you'd like to see?
tj1010
Posts: 201
Joined: Wed May 27, 2015 1:36 pm
Contact:

HTTPRrequest doesn't work on android.

Post by tj1010 »

Code: Select all

;oreintation handling and http demo
Declare drawspecs()
Declare timer()
Declare.l RDesktopHeight()
Declare.l RDesktopWidth()
Global width.l
Global height.l

If OpenWindow(0,0,0,RDesktopWidth(),RDesktopHeight(),"",#PB_Window_Background)
  CanvasGadget(0,0,0,WindowWidth(0),WindowHeight(0),#PB_Canvas_Keyboard)
  AddWindowTimer(0,33,2000)
  BindEvent(#PB_Event_Timer,@timer())
  drawspecs()
EndIf

Procedure timer()
  If EventTimer()=33
    If RDesktopWidth()<>width Or RDesktopHeight()<>height
      width=RDesktopWidth()
      height=RDesktopHeight()
      ResizeWindow(0,0,0,RDesktopWidth(),RDesktopHeight())
      ResizeGadget(0,0,0,WindowWidth(0),WindowHeight(0))
      drawspecs()
    EndIf
  EndIf
EndProcedure

Procedure httpevent(Success, Result$, UserData)
  Protected draw.l
  draw=StartDrawing(CanvasOutput(0))
  DrawingMode(#PB_2DDrawing_Transparent)
  If Success
    DrawText(1,60,"Network: Connected",RGB(255,255,255))
  Else
    DrawText(1,60,"Network: Disconnected",RGB(255,255,255))
  EndIf
  If draw : StopDrawing() : EndIf
EndProcedure

Procedure drawspecs()
  Protected aspect$
  If RDesktopWidth()>RDesktopHeight()
    aspect$="Landscape"
  Else
    aspect$="Verticle"
  EndIf
  StartDrawing(CanvasOutput(0))
  DrawingMode(#PB_2DDrawing_Transparent)
  Box(0,0,WindowWidth(0),WindowHeight(0),RGB(0,0,0))
  DrawText(1,1,"Resolution: "+Str(RDesktopWidth())+"x"+Str(RDesktopHeight()),RGB(255,255,255))
  DrawText(1,33,"Aspect: "+aspect$,RGB(255,255,255))
  StopDrawing()
  HTTPRequest(#PB_HTTP_Get,"https://www.google.com","",@httpevent())
EndProcedure

Procedure.l RDesktopWidth()
  Protected pixels.f
  EnableJS
  v_pixels=window.devicePixelRatio.toPrecision(21);
  DisableJS
  ExamineDesktops()
  ProcedureReturn Val(StrF(pixels * ValF(Str(DesktopWidth(0)))))
EndProcedure

Procedure.l RDesktopHeight()
  Protected pixels.f
  EnableJS
  v_pixels=window.devicePixelRatio.toPrecision(21);
  DisableJS
  ExamineDesktops()
  ProcedureReturn Val(StrF(pixels * ValF(Str(DesktopHeight(0)))))
EndProcedure
0 returned
tj1010
Posts: 201
Joined: Wed May 27, 2015 1:36 pm
Contact:

Re: HTTPRrequest doesn't work on android.

Post by tj1010 »

The remote CGI script or HTTP server needs to set 'Access-Control-Allow-Origin: *' and Android and IOS networking will work. I only tried it with the integrated HTTP call but it should work with escaped websocket and ajax code too.

You'll need to proxy or cache content for services and sites that don't have the wildcard/asterisk set for that header.

Maybe a note in the help file under this function to save a lot of support overhead? If not disable domain policy through the JDK and xcode libs used for it.
Post Reply