Page 1 of 1

HTTPRequest

Posted: Wed Jul 15, 2015 12:44 pm
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().

Re: HTTPRequest

Posted: Wed Jul 15, 2015 1:19 pm
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.

Re: HTTPRequest

Posted: Wed Jul 15, 2015 1:59 pm
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

Re: HTTPRequest

Posted: Wed Jul 15, 2015 7:23 pm
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.