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

HTTPRequest , fails always ?

by plouf Sun Feb 18, 2018 2:43 pm

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

Re: HTTPRequest , fails always ?

by falsam Sun Feb 18, 2018 4:26 pm

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 10 - JDK 1.8 - SB 2.20 - Android 5.5
http://falsam.com

Sorry for my poor english
plouf
 
Posts: 34
Joined: Tue Feb 25, 2014 6:01 pm

Re: HTTPRequest , fails always ?

by plouf Sun Feb 18, 2018 5:06 pm

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

Re: HTTPRequest , fails always ?

by falsam Sun Feb 18, 2018 6:33 pm

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 10 - JDK 1.8 - SB 2.20 - Android 5.5
http://falsam.com

Sorry for my poor english
plouf
 
Posts: 34
Joined: Tue Feb 25, 2014 6:01 pm

Re: HTTPRequest , fails always ?

by plouf Sun Feb 18, 2018 9:34 pm

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
Return to Coding Questions

Who is online

Users browsing this forum: No registered users and 2 guests