HTTPREQUEST() Not Working

Just starting out? Need help? Post your questions and find answers here.
TheMexican
Posts: 17
Joined: Sun Jun 07, 2015 5:58 pm

HTTPREQUEST() Not Working

Post by TheMexican »

I have the following code on a Purebasic program (CGI) and I am using Abyss web server. I know the Purebasic-CGI works because I get the correct reply on a regular webpage http://127.0.0.1/cgi-bin/test.exe.

When I do a httprequest() on Spiderbasic I get an HTTP: Request error

Please help!!

Purebasic Code

Code: Select all

;Initialize CGI and make sure we are able to read request
If Not InitCGI() Or Not ReadCGI()
  End
EndIf

;Create Body of page
jsonresponse.s = "{'name':'This should work'}"

WriteCGIHeader("Access-Control-Allow-Origin", "*")
WriteCGIHeader(#PB_CGI_HeaderContentType, "text/html", #PB_CGI_LastHeader)

WriteCGIString(jsonresponse)
Spiderbasic Code

Code: Select all

; Test interaction between SpiderBasic And Purebasic CGI


theurl.s = "http://127.0.0.1/cgi-bin/test.exe"

Procedure HttpGetEvent(Success, Result$, UserData)
    If Success
      Debug Result$
    Else
      Debug "HTTPRequest(): Error"
      
    EndIf
  EndProcedure
  
  ; Get the content of this file, and display it in the debug window
  
  Debug "Sending Request to " + theurl
  ;
  HTTPRequest(#PB_HTTP_Post, theurl, "", @HttpGetEvent())

TheMexican
Posts: 17
Joined: Sun Jun 07, 2015 5:58 pm

Re: HTTPREQUEST() Not Working

Post by TheMexican »

I finally got it working!!
swan
Posts: 23
Joined: Tue Dec 15, 2015 2:56 am

Re: HTTPREQUEST() Not Working

Post by swan »

Hi, I'm about to embark on something quite similar. Would it be possible to post the working code and perhaps tips, gotchas, etc.
Thanx - Steve ....
TheMexican
Posts: 17
Joined: Sun Jun 07, 2015 5:58 pm

Re: HTTPREQUEST() Not Working

Post by TheMexican »

This weekend I will do some kind of instructions on how to configure CGI to run a Purebasic .exe
I will also put some example code for Purebasic CGI.

So basically there are 3 components to make it all work:
1) Abyss Webserver running CGI
2) Purebasic executable receiving the HTTP_Request, accessing a SQLITE database, and returning JSON
3) Spiderbasic for the web interface and to send requests and to process the JSON responses.


It all works pretty good.
I really don't need to learn HTML5, CSS, Javascript, and a Server scripting language like PHP, Python, etc.

*** I am no expert but I do want Spiderbasic to become a viable alternative for web programming.
swan
Posts: 23
Joined: Tue Dec 15, 2015 2:56 am

Re: HTTPREQUEST() Not Working

Post by swan »

Very much appreciated.
In my instance it will differ a little but the base code should be very close. My server is MS server 2008, so I will be using IIS CGI. And the database is MS SQL server 2008 R2 which doesn't support JSON so I will be passing XML instead.
Looking forward to it.
Cheers .... :D
Post Reply