Page 1 of 1
HTTPRequest , fails always ?
Posted: Sun Feb 18, 2018 2:43 pm
by plouf
why this simple piece of code return's FALSE ?!
offcourse the IS a webserver in the same machine script is executed
Code: Select all
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
;
HTTPRequest(#PB_HTTP_Get, "http://127.0.0.1/","", @HttpGetEvent())
Re: HTTPRequest , fails always ?
Posted: Sun Feb 18, 2018 4:26 pm
by falsam
Save your code : testhttp.sb and try this code
Code: Select all
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
;
HTTPRequest(#PB_HTTP_Get, "testhttp.sb", "", @HttpGetEvent())
Re: HTTPRequest , fails always ?
Posted: Sun Feb 18, 2018 5:06 pm
by plouf
but his is a filename, the idea of httprequest is to read data from ...http domains?
Re: HTTPRequest , fails always ?
Posted: Sun Feb 18, 2018 6:33 pm
by falsam
plouf wrote:but his is a filename, the idea of httprequest is to read data from ...http domains?
Yes, you're right.
So I'm not going to read a text file. I propose a code that will send data to be computed to a Php script.
Code: Select all
Procedure HttpGetEvent(Success, Result$, UserData)
If Success
Debug Result$
Else
Debug "HTTPRequest(): Error"
EndIf
EndProcedure
;Add 3 + 2
HTTPRequest(#PB_HTTP_Post, "calc.php", "action=add&value0=3&value1=2", @HttpGetEvent())
;Subtract 3 - 2
HTTPRequest(#PB_HTTP_Post, "calc.php", "action=subtract&value0=3&value1=2", @HttpGetEvent())
■ And now the Php script. (
calc.php)
Code: Select all
<?php
if( $_SERVER["HTTP_REFERER"] <> "" ) {
$action = $_POST["action"];
switch ($action) {
// Add two values
case "add":
$value0 = $_POST["value0"];
$value1 = $_POST["value1"];
echo $value0 + $value1;
break;
// Subtract two values
case "subtract":
$value0 = $_POST["value0"];
$value1 = $_POST["value1"];
echo $value0 - $value1;
break;
default:
echo "-1";
break;
}
} else {
echo ":)";
}
?>
■ Result on a
real server. Spiderbasic's local server is not Php compatible.
http://falsam.com/sbtest/testhttp.html
Re: HTTPRequest , fails always ?
Posted: Sun Feb 18, 2018 9:34 pm
by plouf
based on your example i have , remember something you have also told me
that javascript can NOT , get data from another domain
127.0.0.1 port 80 is a DIFFERENT domain than spiderbasic server 127.0.0.1 port 8090 ....
putting both files in SAME server it did run... however this app can not be implemented with spider...
thanx for help btw