Send HTTP GET

Moderator: Moderator Group

Send HTTP GET

Postby andreax » Tue Oct 01, 2013 10:15 am

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
andreax
 
Posts: 33
Joined: Thu Aug 02, 2012 6:02 pm

Re: Send HTTP GET

Postby Dennis Kuypers » Tue Oct 01, 2013 10:37 am

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
Dennis Kuypers
Product Developer, Software

Online Manual
User avatar
Dennis Kuypers
coolux Germany
 
Posts: 771
Joined: Thu Jul 05, 2012 12:18 pm

Re: Send HTTP GET

Postby andreax » Tue Oct 01, 2013 11:10 am

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
andreax
 
Posts: 33
Joined: Thu Aug 02, 2012 6:02 pm

Re: Send HTTP GET

Postby Dennis Kuypers » Tue Oct 01, 2013 11:32 am

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
Dennis Kuypers
Product Developer, Software

Online Manual
User avatar
Dennis Kuypers
coolux Germany
 
Posts: 771
Joined: Thu Jul 05, 2012 12:18 pm

Re: Send HTTP GET

Postby andreax » Tue Oct 01, 2013 2:20 pm

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...
andreax
 
Posts: 33
Joined: Thu Aug 02, 2012 6:02 pm

Re: Send HTTP GET

Postby Dennis Kuypers » Tue Oct 01, 2013 4:24 pm

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
Dennis Kuypers
Product Developer, Software

Online Manual
User avatar
Dennis Kuypers
coolux Germany
 
Posts: 771
Joined: Thu Jul 05, 2012 12:18 pm

Re: Send HTTP GET

Postby andreax » Tue Oct 01, 2013 4:38 pm

...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
andreax
 
Posts: 33
Joined: Thu Aug 02, 2012 6:02 pm

Re: Send HTTP GET

Postby Dennis Kuypers » Wed Oct 02, 2013 10:18 am

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
Dennis Kuypers
Product Developer, Software

Online Manual
User avatar
Dennis Kuypers
coolux Germany
 
Posts: 771
Joined: Thu Jul 05, 2012 12:18 pm

Re: Send HTTP GET

Postby andreax » Wed Oct 02, 2013 10:26 am

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
andreax
 
Posts: 33
Joined: Thu Aug 02, 2012 6:02 pm

Re: Send HTTP GET

Postby Dennis Kuypers » Wed Oct 02, 2013 10:32 am

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
Dennis Kuypers
Product Developer, Software

Online Manual
User avatar
Dennis Kuypers
coolux Germany
 
Posts: 771
Joined: Thu Jul 05, 2012 12:18 pm

Re: Send HTTP GET

Postby andreax » Wed Oct 02, 2013 4:04 pm

Damn...wrong revision.
Working like a charm!
Thanks,
Andrea
andreax
 
Posts: 33
Joined: Thu Aug 02, 2012 6:02 pm


Return to Widget Designer V4.7

Who is online

Users browsing this forum: No registered users and 5 guests

cron