Assistance with httprequest

Just starting out? Need help? Post your questions and find answers here.
DeanH
Posts: 8
Joined: Mon May 12, 2014 11:45 pm
Location: Adelaide, South Australia
Contact:

Assistance with httprequest

Post by DeanH »

I have been unable to get httprequest to work with an exe.
I have written a very simple example I have put together.
It works from a webpage but not in SpiderBasic. Here are the details.

The exe is written in PureBasic. Source code is:

Code: Select all

If Not InitCGI() Or Not ReadCGI()
  End
EndIf
a$="<html>"+#CRLF$
a$+"<head>"+#CRLF$
a$+"<title>Test</title>"+#CRLF$
a$+"</head>"+#CRLF$
a$+"<body>"+#CRLF$
a$+"This is a test"+#CRLF$
a$+"</body>"+#CRLF$
a$+"</html>"+#CRLF$
WriteCGIHeader(#PB_CGI_HeaderContentType,"text/html",#PB_CGI_LastHeader)
WriteCGIString(a$)
The file is compiled 64-bit using PB 5.73 as cgitest.exe. The compiling format is Windows.

The test html page is saved as cgitest.htm.

Code: Select all

<html>
<head>
  <title>CGI Test</title>
</head>
<body>
<form action="http://edu0018486/bmv10/cgitest.exe" method="get">
<input type="submit" value="Go">
</form>
</body>
</html>
The webserver is IIS in Windows 10. The folder bmv10 is set up as a virtual directory, shared, with CGI working.
Using Chrome, http://edu0018486/bmv10/cgitest.htm opens the test page. Clicking on Go shows the result correctly.
(I run other pages and apps from the same folder so I know CGI is working there.)

SpiderBasic is installed in the same folder (bmv10).
The SB program code is:

Code: Select all

Procedure HttpGetEvent(Success, Result$, UserData)
  If Success
    Debug Result$
  Else
    Debug "Error"
  EndIf
EndProcedure
HTTPRequest(#PB_HTTP_Get,"http://edu0018486/bmv10/cgitest.exe", "", @HttpGetEvent())
Pressing F5 opens the SB page but the debug window shows "Error". I have tried variations with no success.
Any ideas?
User avatar
Paul
Posts: 195
Joined: Wed Feb 26, 2014 6:46 pm
Location: Canada
Contact:

Re: Assistance with httprequest

Post by Paul »

Pressing F5 opens the SB page but the debug window shows "Error". I have tried variations with no success.
Any ideas?
This tells me you are trying to run SpiderBasic apps from the IDE and contact your Server. You can't do this for security reasons.
As a workaround you need to tweet your PB app to allow for cross site stuff...

Code: Select all

WriteCGIHeader("Access-Control-Allow-Origin", "*") ;<--- Remove for Production

WriteCGIHeader(#PB_CGI_HeaderContentType,"text/html",#PB_CGI_LastHeader)
WriteCGIString(a$)
If you use "Create App" and actually put the SpiderBasic files on your Server you can run you SpiderBasic app without this problem because it would be calling the CGI from the same Server.
DeanH
Posts: 8
Joined: Mon May 12, 2014 11:45 pm
Location: Adelaide, South Australia
Contact:

Re: Assistance with httprequest

Post by DeanH »

Thank you, that worked. I was not aware that was needed for SB. The IIS webserver is on the same computer.
User avatar
Paul
Posts: 195
Joined: Wed Feb 26, 2014 6:46 pm
Location: Canada
Contact:

Re: Assistance with httprequest

Post by Paul »

When you run your SpiderBasic app from the IDE you will notice the web browser is pointing to 127.0.0.1:9080, it's talking to it's own web server the IDE runs in the background.
Post Reply