HTTPRequest

Just starting out? Need help? Post your questions and find answers here.
Angelo
Posts: 15
Joined: Tue Jul 14, 2015 9:14 am

HTTPRequest

Post by Angelo »

In PureBasic I use the WinApi function

Code: Select all

 URLDownloadToFile_(#Null, "http://mydomain/mydatabase.php?name=Angelo&age=37", "result.txt", #Null, #Null)
to send the values of the two parameters name and age to the php-script mydatabase.php, which has the function to open a mysql database and save the transmitted data. A possible answer of the php-script via exit() - e.g. exit("transaction war successful"); - is stored in the text file result.txt then.
(one can also use the PB command ReceiveHTTPFile() or the comfortable callback solution by - I think - Hexor)
I tried this within SpiderBasic by using the HTTPRequest-function:

Code: Select all

Procedure HttpGetEvent(Success, Result$, UserData)
   If Success
      Debug Result$
   Else
      Debug "HTTPRequest(): Error"
   EndIf
EndProcedure

 HTTPRequest(#PB_HTTP_Get, "http://mydomain/mydatabase.php?name=Angelo&age=37", "", @HttpGetEvent())
But only the error message is displayed. My question is, whether I'm on the right way by using HttpGetEvent().
bbanelli
Posts: 107
Joined: Mon Jul 13, 2015 7:40 am

Re: HTTPRequest

Post by bbanelli »

Have you taken into consideration fact from documentation:
Due to security constraints, it is only possible to execute a request on the same domain.
I would only guess that if you are trying to debug you will fail unless you migrate all to some sort of local server where you can test it.
"If you lie to the compiler, it will get its revenge."
Henry Spencer
http://www.pci-z.com/
Angelo
Posts: 15
Joined: Tue Jul 14, 2015 9:14 am

Re: HTTPRequest

Post by Angelo »

That is a good point. That's why I defined a TextGadget which I use instead of debug. The callback function actually looks like this:

Code: Select all

Procedure HttpGetEvent(Success, Result$, UserData)
   If Success
      SetGadgetText(#text,  "yeah, it worked!")
   Else
      SetGadgetText(#text, "sorry, error occured!")
   EndIf
EndProcedure
Angelo
Posts: 15
Joined: Tue Jul 14, 2015 9:14 am

Re: HTTPRequest

Post by Angelo »

Problem solved:
Although not using any Umlauts or spaces, I applied the function UrlEncoder() for the URL string. And now everything works as it should.
Post Reply