HTTPRequest , fails always ?

Just starting out? Need help? Post your questions and find answers here.
plouf
Posts: 194
Joined: Tue Feb 25, 2014 6:01 pm
Location: Athens,Greece

HTTPRequest , fails always ?

Post 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())
Christos
falsam
Posts: 280
Joined: Mon May 05, 2014 9:49 pm
Location: France
Contact:

Re: HTTPRequest , fails always ?

Post 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())

➽ Windows 11 - JDK 1.8 - SB 2.40 - Android 13
http://falsam.com

Sorry for my poor english
plouf
Posts: 194
Joined: Tue Feb 25, 2014 6:01 pm
Location: Athens,Greece

Re: HTTPRequest , fails always ?

Post by plouf »

but his is a filename, the idea of httprequest is to read data from ...http domains?
Christos
falsam
Posts: 280
Joined: Mon May 05, 2014 9:49 pm
Location: France
Contact:

Re: HTTPRequest , fails always ?

Post 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.

:arrow: http://falsam.com/sbtest/testhttp.html

➽ Windows 11 - JDK 1.8 - SB 2.40 - Android 13
http://falsam.com

Sorry for my poor english
plouf
Posts: 194
Joined: Tue Feb 25, 2014 6:01 pm
Location: Athens,Greece

Re: HTTPRequest , fails always ?

Post 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
Christos
Post Reply