Page 1 of 1

Send HTTP GET

PostPosted: Tue Oct 01, 2013 10:15 am
by andreax
Hi,
is there a way to send HTTP GET request (a normal HTTP URL) with Widget designer standard?
I need to use it to control some relay board that support only HTTP request.
Thanks,
Andrea

Re: Send HTTP GET

PostPosted: Tue Oct 01, 2013 10:37 am
by Dennis Kuypers
Hi Andrea,

you can create a simple TCP Socket and send a HTTP request like http://10.0.0.3/control.cgi?mode=0&othermode=widget to port 80 (default)

Code: Select all
TCPSend,1,GET /control.cgi?mode=0&othermode=widget HTTP/1.1[CR][LF]Host: 10.0.0.3[CR][LF]User-Agent: Widget-Designer[CR][LF]Connection: close[CR][LF][CR][LF]


I strongly recommend you to Stop the connection after every request and only start it when you have something to send.

Best regards
Dennis

Re: Send HTTP GET

PostPosted: Tue Oct 01, 2013 11:10 am
by andreax
WOW you were fast!!!
I've tried exactly what you posted (of course changing IP and GET string), but it doesn't work.
Is there a way to see the Widget LOG to see what's wrong?
Thanks,
Andrea

Re: Send HTTP GET

PostPosted: Tue Oct 01, 2013 11:32 am
by Dennis Kuypers
Hi,

you can go to the connection manager and right click on the connection. Choose "Test", then you can see what the server responds.

Post it here

Edit: I forgot to mention that you have to set up the TCP connection before you can use the command.

Best regards
Dennis

Re: Send HTTP GET

PostPosted: Tue Oct 01, 2013 2:20 pm
by andreax
Here are my lines:

Code: Select all
TCPStart,1
Connection: open
TCPSend,1,GET /leds.cgi?led=a
Host: 192.168.0.31
User-Agent: Widget-Designer
Connection: close
TCPStop,1


But it still doesn't work.

If I go in the connection manager and I create the connection to that IP to port 80 it connects. If I click on test I get a blank windows where I can write in, but nothing happen...

Re: Send HTTP GET

PostPosted: Tue Oct 01, 2013 4:24 pm
by Dennis Kuypers
Hi,

You are mixing things. Please use [CR][LF] instead of "real" line breaks.
- You left out the " HTTP/1.1" part.
- The Connection: close part is optional, I included it because your client is going to disconnect anyway.
- HTTP Protocol requires two times "[CR][LF]" after the Headers
- I added WDWait,1 to give the server time to respond

Code: Select all
TCPStart,1
TCPSend,1,GET /leds.cgi?led=a HTTP/1.1[CR][LF]Host: 192.168.0.31[CR][LF]User-Agent: Widget-Designer[CR][LF]Connection: close[CR][LF][CR][LF]
WDWait,1
TCPStop,1


The window will show you the response from the server

Re: Send HTTP GET

PostPosted: Tue Oct 01, 2013 4:38 pm
by andreax
...nothing :(
I've pasted your exact code but nothing happen, while on the browser the url 192.168.0.31/leds.cgi?led=a works.
On the Connection Manager the test window is empty.
What may I be doing wrong?
Thanks again,
Andrea

Re: Send HTTP GET

PostPosted: Wed Oct 02, 2013 10:18 am
by Dennis Kuypers
Hi,

I completely forgot about the (rather new) HttpRequest command! (Revision 456 or higher required)

Try
HTTPRequest,http://192.168.0.31/leds.cgi?led=a

Best regards
Dennis

Re: Send HTTP GET

PostPosted: Wed Oct 02, 2013 10:26 am
by andreax
Well...how to use it into the widget?
What should be the complete script?
Sorry for this very basic request but I'm starting now to use the Widget.
Thanks,
Andrea

Re: Send HTTP GET

PostPosted: Wed Oct 02, 2013 10:32 am
by Dennis Kuypers
Hi,

That is all it needs. Create a CustomScriptButton and put this in the onclick text field:

Code: Select all
HTTPRequest,http://192.168.0.31/leds.cgi?led=a


Best regards
Dennis

Re: Send HTTP GET

PostPosted: Wed Oct 02, 2013 4:04 pm
by andreax
Damn...wrong revision.
Working like a charm!
Thanks,
Andrea