If you need to call a URL from a Cisco router (example: call a Web Service which will send an email...) as you would do using a WGET on a UNIX or Windows computer, here are two ways of doing it:
1. Using an IP SLA
ip sla 10
http raw http://core-layer.com version 1.1
GET /script.html?param1=1 HTTP/1.1\r\n
Authorization: Basic YWRtaW46cGFzc3dvcmQ=\r\n
The section http-raw-request will allow you to add HTTP headers if needed: for example, « Authorization: » header will allow the router to authenticate to the web page. That header si followed by authentication type (here « Basic ») and the string encoded in Base64: « username:password ». Which gives YWRtaW46cGFzc3dvcmQ= for admin:password .
You can then start the SLA using ip sla schedule 10...
2. Using a TCL script
The same kind of request can be created using a TCL script (saved in router's flash memory for example) and then directly called for the CLI with tclsh flash:script.tcl arg1 arg2 arg3 ...
Here is an example of TCL script saved in flash:
set arg1 [lindex $argv 0]
http::geturl " http://core-layer.com/script.html?param1=$arg1" -headers "Connection keep-alive Authorization \"Basic YWRtaW46cGFzc3dvcmQ=\""
Here are a couple comments on that script
- Many TCL script examples will tell you to add the reference to http this way:
package require http
Yet, Cisco stores librairies in « tmpsys:lib/tcl/» hence the following command:
- To add HTTP headers you have to add parameter -headers which is then followed by headers formatted this way:
Header1 Value1 Header2 Value2 Header3 Value3 ...
So you should always have an even number of strings after parameter -headers . If a header requires a value with spaces in it you have to escape " using \" .
We have been using Cisco for our class for over a year now, and this is the first problem that we encountered. It is really inconvenient for it to happen at such a time. I am willing to pay you extra if you are able to fix this as soon as possible. I may sound rude here, but we really need to use it immediately. I cannot give my students a grade without it, so please, help me out here.
Hello nice bloog
Leave a Reply.