Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 09:39 27 Nov 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Webmite : how to call a php script

Author Message
Plasmamac

Guru

Joined: 31/01/2019
Location: Germany
Posts: 554
Posted: 12:18pm 14 Nov 2023
Copy link to clipboard 
Print this post

Hi ,
I try to send a variable to a php script . Even i like to read the Answer from the script.

Can anyone help?

Thx
Plasma
 
TheMonkeys

Regular Member

Joined: 15/12/2022
Location: Australia
Posts: 59
Posted: 03:26am 15 Nov 2023
Copy link to clipboard 
Print this post

What variable(s) would you like to send/receive?

Cheers,

Chris.
 
Plasmamac

Guru

Joined: 31/01/2019
Location: Germany
Posts: 554
Posted: 04:05am 15 Nov 2023
Copy link to clipboard 
Print this post

a statusstring
Plasma
 
TheMonkeys

Regular Member

Joined: 15/12/2022
Location: Australia
Posts: 59
Posted: 04:13am 15 Nov 2023
Copy link to clipboard 
Print this post

The simplest for the scripts I use is usually
script.php?var=123&statustring=hello

I've been mucking around with php for a decade or two.

Cheers,

Chris.
 
TheMonkeys

Regular Member

Joined: 15/12/2022
Location: Australia
Posts: 59
Posted: 02:28am 16 Nov 2023
Copy link to clipboard 
Print this post

Well, I've got this far...

Function getTest(servaddr$,servport,tcpreq$) As string
 Local return%(64) ' 512 chars
 WEB OPEN TCP CLIENT servaddr$, servport%
   WEB TCP CLIENT REQUEST tcpreq$+" HTTP/1.1"+Chr$(10)+Chr$(13), return%()
   getTest$="done"
   LongString Print return%()
 WEB CLOSE TCP CLIENT

getTest("192.168.0.32",8081,"GET /status/ldata.php")

spits to the console:

HTTP/1.1 400 Bad Request
Date: Thu, 16 Nov 2023 01:53:46 GMT
Server: Apache/2.4.25 (Debian)
Content-Length: 301
Connection: close
Content-Type: text/html; charset=iso-8859-1
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
<hr>
.......... etc

This is a local server, and a known good request (eg: http://192.168.0.32:8081/status/ldata.php works)

Still, it's a start.

Cheers,

Chris
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3802
Posted: 07:45am 16 Nov 2023
Copy link to clipboard 
Print this post

It may not -probably does not - like that you send LF then CR.

(Being chr$(10) then chr$(13).)

A previous webserver didn't like them in the wrong order.

John
 
TheMonkeys

Regular Member

Joined: 15/12/2022
Location: Australia
Posts: 59
Posted: 08:09am 16 Nov 2023
Copy link to clipboard 
Print this post

  JohnS said  It may not -probably does not - like that you send LF then CR.

(Being chr$(10) then chr$(13).)

A previous webserver didn't like them in the wrong order.

John

Spot On John!
Function getTest(servaddr$,servport,tcpreq$) As string
Local return%(64) ' 512 chars
WEB OPEN TCP CLIENT servaddr$, servport
getTest$="GET "+tcpreq$+" HTTP/1.1"+Chr$(13)+Chr$(10)+"Host: "+servaddr$+":"+Str$(servport)+Chr$(13)+Chr$(10)+"Connection: keep-alive"+Chr$(13)+Chr$(10)+Chr$(13)+Chr$(10)
WEB TCP CLIENT REQUEST getTest$, return%()
LongString Print return%() ' for now
WEB CLOSE TCP CLIENT
End Function

Now works like a charm.

Calling getTest("192.168.0.32",8081,"/status/ldata.php") spits back exactly what I expected.

Cheers, Chief.

Chris
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 3802
Posted: 01:20pm 16 Nov 2023
Copy link to clipboard 
Print this post

I wish all bugs could be found & fixed so quickly!

John
 
Plasmamac

Guru

Joined: 31/01/2019
Location: Germany
Posts: 554
Posted: 02:53pm 16 Nov 2023
Copy link to clipboard 
Print this post

Thx a lot


Works like a charm
Plasma
 
TheMonkeys

Regular Member

Joined: 15/12/2022
Location: Australia
Posts: 59
Posted: 04:33am 17 Nov 2023
Copy link to clipboard 
Print this post

Not a problem, sir.

you should be able to use the usual eg "scriptname.php?var1=10&var2=fred" to pass variables, although I'm unsure about the webmite handling spaces in strings.

Cheers,

Chris.
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024