[Qt-interest] QT power switch

Josiah Bryan jbryan at productiveconcepts.com
Mon Nov 23 18:10:38 CET 2009


luis navarro wrote:
> Well, the html posted it's the welcome page. When you get in, you can 
> see the options to turn off and on the outlets. But when you make some 
> clicks to do that, on address bar i see -> 
> http://mypowerswitch/outlet?1=ON. So i thought i could go forward to 
> this action loging me first.
> 
> By other way, i was trying to make an analog code from this perl code 
> that works fine for this objective.
> 
> use LWP::UserAgent;
> $ua = LWP::UserAgent->new();
> $ua->get('http://user:xxxx@mypowerswitch/outlet?1=ON);

Well, none of the Qt/C++ code you posted (below) includes a user/pass 
combination in it the URL. Did you try including the user/pass in the Qt 
URL string in the same format as you did to the get() call above?

> 
> 
> 2009/11/23 Josiah Bryan <jbryan at productiveconcepts.com 
> <mailto:jbryan at productiveconcepts.com>>
> 
> 
>     luis navarro wrote:
> 
>         Hi all.
> 
>         I have a problem and i hope you can help me.
> 
>         There is a web server embebbed into a web power switch which
>         controls 8 AC electric outlets. I'm trying to use QT to turn on
>         and off one oultet (outlet #1) with a button. I have been trying
>         with QHttp, QWebview but i'm not even near i think...
> 
>         I hope you can give some advices or guide.
>         Thanks
> 
> 
>     Are you reading the HTML you posted? Its a login page - complete
>     with a challenge. Are you logging in first to the powerswitch then
>     trying to send the ON command?
> 
> 
>         *code 1*
> 
> 
>         void MainWindow::webPowerSwitch(){
> 
>         QUrl url("http://mywebpowerswitch:9997");
> 
>         QHttp::ConnectionMode mode = url.scheme().toLower() == "https" ?
>         QHttp::ConnectionModeHttps : QHttp::ConnectionModeHttp;
> 
>         http->setHost(url.host(), mode, url.port() == -1 ? 80 : url.port());
> 
>         QByteArray path = QUrl::toPercentEncoding(url.path(),
>         "!$&'()*+,;=:@/");
> 
>         http->setUser("user","xxxx");
> 
>         if (path.isEmpty())
> 
>         path = "/outlet?1=ON";
> 
>         qDebug()<<path;
> 
>         http->get(path);
> 
>         }
> 
>         *code 2*
> 
>         void MainWindow::webPowerSwitch(){
> 
>         QUrl url("http://mywebpowerswitch:9997/outlet?1=ON");
> 
>         url.setUserName("user");
> 
>         url.setPassword("xxxx");
> 
>         outletwebview->load(url);
> 
>         }
> 
>         *code 3*
> 
>         void MainWindow::webPowerSwitch(){
> 
>         QUrl url("http://mywebpowerswitch:9997/outlet?1=ON");
> 
>         url.setUserName("user");
> 
>         url.setPassword("xxxx");
> 
>         QNetworkRequest nR = QNetworkRequest(url);
> 
>         outletwebview->load(nR,QNetworkAccessManager::GetOperation);
> 
>         }
> 
> 
>         *code 4*
> 
>         void MainWindow::webPowerSwitch(){
> 
>         QUrl url("http://mypowerswitch:9997/outlet?1=ON"):
> 
>         url.setUserName("user");
> 
>         url.setPassword("xxxx");
> 
>         QNetworkAccessManager *networkManager =
>         outletwebview->page()->networkAccessManager();
> 
>         QNetworkRequest request(url);
> 
>         networkManager->get(request);
> 
>         }
> 
>         *
>         webpowerswitch code:*
>         <html>
> 
>         <head>
> 
>         <META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
> 
>         <title>Power Controller </title>
> 
>         <script language="javascript" src="/md5.js"></script>
> 
>         <script language="javascript">
> 
>         <!--
> 
>         function calcResponse(){
> 
>         var str;
> 
>         str=document.login.Username.value+document.login.Password.value+document.login.Challenge.value;
> 
>         document.secin.Password.value = hex_md5(str);
> 
>         document.secin.Username.value = document.login.Username.value;
> 
>         document.secin.submit();
> 
>         }//-->
> 
>         </script>
> 
>         </head>
> 
>         <body>
> 
>         <noscript>
> 
>         <table width="100%" border=0>
> 
>         <tr><td bgcolor=red>&nbsp;</td></tr>
> 
>         <tr><td align=center><h1>Warning: Insecure
>         Authentication</h1></td></tr>
> 
>         <tr><td bgcolor=red>&nbsp;</td></tr></table>
> 
>         </noscript>
> 
>         <FORM NAME="login" ID="login" ACTION="/login.tgi" METHOD=post>
> 
>         <TABLE BORDER="0">
> 
>         <TR>
> 
>         <TD>User Name</TD>
> 
>         <TD><INPUT TYPE="text" NAME="Username" VALUE="" MAXLENGTH=32></TD>
> 
>         </TR>
> 
>         <TR>
> 
>         <TD>Password</TD>
> 
>         <TD><INPUT TYPE="password" NAME="Password" MAXLENGTH=32></TD>
> 
>         </TR>
> 
>         <TR ALIGN=RIGHT>
> 
>         <TD></TD>
> 
>         <TD><INPUT onClick="calcResponse(); return false;" TYPE="Submit"
>         NAME="Submitbtn" VALUE="OK">
> 
>         <input type="hidden" name="Challenge" value="HFLS3zz/Y1tbPrk">
> 
>         </TD></TR>
> 
>         </TABLE>
> 
>         </FORM>
> 
>         <script language="javascript">
> 
>         <!--
> 
>         document.login.Username.focus();
> 
>         //-->
> 
>         </script>
> 
>         <FORM NAME="secin" ID="secin" ACTION="/login.tgi" METHOD=post>
> 
>         <INPUT TYPE=""
> 
>         mensaje llego
> 
>         "hidden" NAME="Username">
> 
>         <INPUT TYPE="hidden" NAME="Password">
> 
>         </FORM>
> 
>         </body>
> 
>         </html>
> 
> 
> 
>         ------------------------------------------------------------------------
> 
> 
>         _______________________________________________
>         Qt-interest mailing list
>         Qt-interest at trolltech.com <mailto:Qt-interest at trolltech.com>
>         http://lists.trolltech.com/mailman/listinfo/qt-interest
> 
> 
>     -- 
> 
>     -=-=-=-=-=-=-=-=-=-=-=-=-
>     Josiah Bryan
>     Productive Concepts, Inc.
>     jbryan at pciint.com <mailto:jbryan at pciint.com>
>     (765) 964-6009, ext. 224
> 
> 
> 
> 
> -- 
> Atte.
> Luis Navarro Domínguez
> luis.navarro at jro.igp.gob.pe <mailto:luis.navarro at jro.igp.gob.pe>
> LISN Department
> Jicamarca Radio Observatory
> Geophysical Institute of Peru
> Apartado 13-0207
> Lima 13 - Peru
> Telf: (51)-1-3172313
> Fax: (51)-1-3172312
> http://jro.igp.gob.pe/

-- 

-=-=-=-=-=-=-=-=-=-=-=-=-
Josiah Bryan
Productive Concepts, Inc.
jbryan at pciint.com
(765) 964-6009, ext. 224




More information about the Qt-interest-old mailing list