webclient POST problem

StijnDP

New member
Joined
Aug 30, 2006
Messages
1
Location
Belgium
Programming Experience
1-3
Hi, I'm trying to send a HTTP POST to my APC MasterSwitch. I use the following code:

VB.NET:
[SIZE=2][COLOR=#0000ff]Option [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Explicit [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]On[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Option [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Strict [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]On[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Imports[/COLOR][/SIZE][SIZE=2] System[/SIZE]
[SIZE=2][COLOR=#0000ff]Imports[/COLOR][/SIZE][SIZE=2] System.Net[/SIZE]
[SIZE=2][COLOR=#0000ff]Imports[/COLOR][/SIZE][SIZE=2] System.Text[/SIZE]
[SIZE=2][COLOR=#0000ff]Public [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Class[/COLOR][/SIZE][SIZE=2] APCMasterSwitch[/SIZE]
 
[SIZE=2][COLOR=#0000ff]Public [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Function[/COLOR][/SIZE][SIZE=2] SetState([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] strPort1s [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] strPort2s [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] strPort3s [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] strPort4s [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2], _[/SIZE]
[SIZE=2][COLOR=#0000ff]   ByVal[/COLOR][/SIZE][SIZE=2] strPort5s [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] strPort6s [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] strPort7s [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] strPort8s [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2]) [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE]
 
[SIZE=2][COLOR=#008000]   'Declarations[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]   Dim[/COLOR][/SIZE][SIZE=2] webCl [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] WebClient[/SIZE]
[SIZE=2][COLOR=#0000ff]   Dim[/COLOR][/SIZE][SIZE=2] strAPCCommand, strUsername, strPassword, strHost [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]   Dim[/COLOR][/SIZE][SIZE=2] strPort1, strPort2, strPort3, strPort4, strPort5, strPort6, strPort7, strPort8 [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE]
 
[SIZE=2][COLOR=#008000]   'Config[/COLOR][/SIZE]
[SIZE=2]   strUsername = [/SIZE][SIZE=2][COLOR=#800000]"admin"[/COLOR][/SIZE]
[SIZE=2]   strPassword = [/SIZE][SIZE=2][COLOR=#800000]"password"[/COLOR][/SIZE]
[SIZE=2]   strHost = [/SIZE][SIZE=2][COLOR=#800000]"host"[/COLOR][/SIZE]
 
[SIZE=2][COLOR=#008000]   'Determination of APC command string[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]   Select [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] strPort1s[/SIZE]
[SIZE=2][COLOR=#0000ff]      Case [/COLOR][/SIZE][SIZE=2][COLOR=#800000]"On"[/COLOR][/SIZE]
[SIZE=2]          strPort1 = [/SIZE][SIZE=2][COLOR=#800000]"66000000"[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]      Case [/COLOR][/SIZE][SIZE=2][COLOR=#800000]"Off"[/COLOR][/SIZE]
[SIZE=2]          strPort1 = [/SIZE][SIZE=2][COLOR=#800000]"67000000"[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]      Case [/COLOR][/SIZE][SIZE=2][COLOR=#800000]""[/COLOR][/SIZE]
[SIZE=2]          strPort1 = [/SIZE][SIZE=2][COLOR=#800000]"65000000"[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]      Case [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Else[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]          Throw [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Exception([/SIZE][SIZE=2][COLOR=#800000]"Not yet implemented in current API"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#0000ff]          Exit [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Function[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]   End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Select[/COLOR][/SIZE]
 
[SIZE=2][COLOR=#0000ff]   Select [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] strPort2s[/SIZE]
[SIZE=2][COLOR=#0000ff]      Case [/COLOR][/SIZE][SIZE=2][COLOR=#800000]"On"[/COLOR][/SIZE]
[SIZE=2]          strPort2 = [/SIZE][SIZE=2][COLOR=#800000]"ca000000"[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]      Case [/COLOR][/SIZE][SIZE=2][COLOR=#800000]"Off"[/COLOR][/SIZE]
[SIZE=2]          strPort2 = [/SIZE][SIZE=2][COLOR=#800000]"cb000000"[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]      Case [/COLOR][/SIZE][SIZE=2][COLOR=#800000]""[/COLOR][/SIZE]
[SIZE=2]          strPort2 = [/SIZE][SIZE=2][COLOR=#800000]"c9000000"[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]      Case [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Else[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]          Throw [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Exception([/SIZE][SIZE=2][COLOR=#800000]"Not yet implemented in current API"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#0000ff]          Exit [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Function[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]   End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Select[/COLOR][/SIZE]
 
[SIZE=2][COLOR=#0000ff]   Select [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] strPort3s[/SIZE]
[SIZE=2][COLOR=#0000ff]      Case [/COLOR][/SIZE][SIZE=2][COLOR=#800000]"On"[/COLOR][/SIZE]
[SIZE=2]          strPort3 = [/SIZE][SIZE=2][COLOR=#800000]"2e010000"[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]      Case [/COLOR][/SIZE][SIZE=2][COLOR=#800000]"Off"[/COLOR][/SIZE]
[SIZE=2]          strPort3 = [/SIZE][SIZE=2][COLOR=#800000]"2f010000"[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]      Case [/COLOR][/SIZE][SIZE=2][COLOR=#800000]""[/COLOR][/SIZE]
[SIZE=2]          strPort3 = [/SIZE][SIZE=2][COLOR=#800000]"2d010000"[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]      Case [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Else[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]          Throw [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Exception([/SIZE][SIZE=2][COLOR=#800000]"Not yet implemented in current API"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#0000ff]          Exit [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Function[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]    End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Select[/COLOR][/SIZE]
 
[SIZE=2][COLOR=#0000ff]    Select [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] strPort4s[/SIZE]
[SIZE=2][COLOR=#0000ff]       Case [/COLOR][/SIZE][SIZE=2][COLOR=#800000]"On"[/COLOR][/SIZE]
[SIZE=2]           strPort4 = [/SIZE][SIZE=2][COLOR=#800000]"92010000"[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]       Case [/COLOR][/SIZE][SIZE=2][COLOR=#800000]"Off"[/COLOR][/SIZE]
[SIZE=2]           strPort4 = [/SIZE][SIZE=2][COLOR=#800000]"93010000"[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]       Case [/COLOR][/SIZE][SIZE=2][COLOR=#800000]""[/COLOR][/SIZE]
[SIZE=2]           strPort4 = [/SIZE][SIZE=2][COLOR=#800000]"91010000"[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]       Case [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Else[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]           Throw [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Exception([/SIZE][SIZE=2][COLOR=#800000]"Not yet implemented in current API"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#0000ff]           Exit [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Function[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]    End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Select[/COLOR][/SIZE]
 
[SIZE=2][COLOR=#0000ff]    Select [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] strPort5s[/SIZE]
[SIZE=2][COLOR=#0000ff]       Case [/COLOR][/SIZE][SIZE=2][COLOR=#800000]"On"[/COLOR][/SIZE]
[SIZE=2]           strPort5 = [/SIZE][SIZE=2][COLOR=#800000]"f6010000"[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]       Case [/COLOR][/SIZE][SIZE=2][COLOR=#800000]"Off"[/COLOR][/SIZE]
[SIZE=2]           strPort5 = [/SIZE][SIZE=2][COLOR=#800000]"f7010000"[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]       Case [/COLOR][/SIZE][SIZE=2][COLOR=#800000]""[/COLOR][/SIZE]
[SIZE=2]           strPort5 = [/SIZE][SIZE=2][COLOR=#800000]"f5010000"[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]       Case [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Else[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]           Throw [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Exception([/SIZE][SIZE=2][COLOR=#800000]"Not yet implemented in current API"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#0000ff]            Exit [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Function[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]    End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Select[/COLOR][/SIZE]
 
[SIZE=2][COLOR=#0000ff]    Select [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] strPort6s[/SIZE]
[SIZE=2][COLOR=#0000ff]       Case [/COLOR][/SIZE][SIZE=2][COLOR=#800000]"On"[/COLOR][/SIZE]
[SIZE=2]           strPort6 = [/SIZE][SIZE=2][COLOR=#800000]"5a020000"[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]       Case [/COLOR][/SIZE][SIZE=2][COLOR=#800000]"Off"[/COLOR][/SIZE]
[SIZE=2]           strPort6 = [/SIZE][SIZE=2][COLOR=#800000]"5b020000"[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]       Case [/COLOR][/SIZE][SIZE=2][COLOR=#800000]""[/COLOR][/SIZE]
[SIZE=2]           strPort6 = [/SIZE][SIZE=2][COLOR=#800000]"59020000"[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]       Case [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Else[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]           Throw [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Exception([/SIZE][SIZE=2][COLOR=#800000]"Not yet implemented in current API"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#0000ff]            Exit [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Function[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]    End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Select[/COLOR][/SIZE]
 
[SIZE=2][COLOR=#0000ff]   Select [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] strPort7s[/SIZE]
[SIZE=2][COLOR=#0000ff]      Case [/COLOR][/SIZE][SIZE=2][COLOR=#800000]"On"[/COLOR][/SIZE]
[SIZE=2]          strPort7 = [/SIZE][SIZE=2][COLOR=#800000]"be020000"[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]      Case [/COLOR][/SIZE][SIZE=2][COLOR=#800000]"Off"[/COLOR][/SIZE]
[SIZE=2]          strPort7 = [/SIZE][SIZE=2][COLOR=#800000]"bf020000"[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]      Case [/COLOR][/SIZE][SIZE=2][COLOR=#800000]""[/COLOR][/SIZE]
[SIZE=2]          strPort7 = [/SIZE][SIZE=2][COLOR=#800000]"bd020000"[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]      Case [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Else[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]           Throw [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Exception([/SIZE][SIZE=2][COLOR=#800000]"Not yet implemented in current API"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#0000ff]           Exit [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Function[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]   End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Select[/COLOR][/SIZE]
 
[SIZE=2][COLOR=#0000ff]   Select [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] strPort8s[/SIZE]
[SIZE=2][COLOR=#0000ff]       Case [/COLOR][/SIZE][SIZE=2][COLOR=#800000]"On"[/COLOR][/SIZE]
[SIZE=2]           strPort8 = [/SIZE][SIZE=2][COLOR=#800000]"22030000"[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]       Case [/COLOR][/SIZE][SIZE=2][COLOR=#800000]"Off"[/COLOR][/SIZE]
[SIZE=2]           strPort8 = [/SIZE][SIZE=2][COLOR=#800000]"23030000"[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]       Case [/COLOR][/SIZE][SIZE=2][COLOR=#800000]""[/COLOR][/SIZE]
[SIZE=2]           strPort8 = [/SIZE][SIZE=2][COLOR=#800000]"21030000"[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]       Case [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Else[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]           Throw [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Exception([/SIZE][SIZE=2][COLOR=#800000]"Not yet implemented in current API"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#0000ff]           Exit [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Function[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]    End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Select[/COLOR][/SIZE]
 
[SIZE=2][COLOR=#008000]   'Creation of the APC Command string[/COLOR][/SIZE]
[SIZE=2]   strAPCCommand = [/SIZE][SIZE=2][COLOR=#800000]"HX=hr&HX2=hr&OutCtl="[/COLOR][/SIZE][SIZE=2] & strPort1 & [/SIZE][SIZE=2][COLOR=#800000]"&OutCtl="[/COLOR][/SIZE][SIZE=2] & strPort2 & [/SIZE][SIZE=2][COLOR=#800000]"&OutCtl="[/COLOR][/SIZE][SIZE=2] & strPort3 & [/SIZE][SIZE=2][COLOR=#800000]"&OutCtl="[/COLOR][/SIZE][SIZE=2] & strPort4 & [/SIZE][SIZE=2][COLOR=#800000]"&OutCtl="[/COLOR][/SIZE][SIZE=2] & strPort5 & [/SIZE][SIZE=2][COLOR=#800000]"&OutCtl="[/COLOR][/SIZE][SIZE=2] & strPort6 & [/SIZE][SIZE=2][COLOR=#800000]"&OutCtl="[/COLOR][/SIZE][SIZE=2] & strPort7 & [/SIZE][SIZE=2][COLOR=#800000]"&OutCtl="[/COLOR][/SIZE][SIZE=2] & strPort8[/SIZE]
 
[SIZE=2][COLOR=#008000]   'Sending some headers[/COLOR][/SIZE]
[SIZE=2]   webCl.Headers.Add(HttpRequestHeader.Accept, [/SIZE][SIZE=2][COLOR=#800000]"image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]   webCl.Headers.Add(HttpRequestHeader.Referer, [/SIZE][SIZE=2][COLOR=#800000]"http://"[/COLOR][/SIZE][SIZE=2] & strHost & [/SIZE][SIZE=2][COLOR=#800000]"/outlets.htm"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]   webCl.Headers.Add(HttpRequestHeader.AcceptEncoding, [/SIZE][SIZE=2][COLOR=#800000]"gzip, deflate"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]   webCl.Headers.Add(HttpRequestHeader.ContentType, [/SIZE][SIZE=2][COLOR=#800000]"application/x-www-form-urlencoded"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]   webCl.Headers.Add(HttpRequestHeader.UserAgent, [/SIZE][SIZE=2][COLOR=#800000]"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]   webCl.Headers.Add(HttpRequestHeader.CacheControl, [/SIZE][SIZE=2][COLOR=#800000]"no-cache"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]   webCl.Headers.Add(HttpRequestHeader.Authorization, [/SIZE][SIZE=2][COLOR=#800000]"Basic "[/COLOR][/SIZE][SIZE=2] & LoginToBase64(strUsername, strPassword))[/SIZE]
 
[COLOR=green]   'Sending the POST[/COLOR]
[SIZE=2]    webCl.UploadString([/SIZE][SIZE=2][COLOR=#800000]"http://"[/COLOR][/SIZE][SIZE=2] & strHost & [/SIZE][SIZE=2][COLOR=#800000]"/Forms/outlets2"[/COLOR][/SIZE][SIZE=2], strAPCCommand)[/SIZE]
 
[SIZE=2][COLOR=#0000ff]   Return [/COLOR][/SIZE][SIZE=2][COLOR=#800000]"Succes"[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Function[/COLOR][/SIZE]
 
 
[SIZE=2][COLOR=#0000ff]Private [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Function[/COLOR][/SIZE][SIZE=2] LoginToBase64([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] strUsername [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] strPassword [/SIZE][SIZE=2][COLOR=#0000ff]As [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2]) [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]   Dim[/COLOR][/SIZE][SIZE=2] bteBase64 [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Byte[/COLOR][/SIZE][SIZE=2]()[/SIZE]
[SIZE=2]   bteBase64 = Encoding.ASCII.GetBytes(strUsername & [/SIZE][SIZE=2][COLOR=#800000]":"[/COLOR][/SIZE][SIZE=2] & strPassword)[/SIZE]
[SIZE=2][COLOR=#0000ff]   Return[/COLOR][/SIZE][SIZE=2] Convert.ToBase64String(bteBase64)[/SIZE]
[SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Function[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]End [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Class[/COLOR][/SIZE]

The problem is that the 'strAPCCommand' string doesn't get sent to the APC. I sniffed the traffic and I get this:
VB.NET:
[COLOR=darkred]POST /Forms/outlets2 HTTP/1.1[/COLOR]
[COLOR=darkred]Accept-Encoding: gzip, deflate[/COLOR]
[COLOR=darkred]Cache-Control: no-cache[/COLOR]
[COLOR=darkred]Authorization: Basic [Base64 string][/COLOR]
[COLOR=darkred]Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*[/COLOR]
[COLOR=darkred]Content-Type: application/x-www-form-urlencoded[/COLOR]
[COLOR=darkred]Referer: [/COLOR][URL="http://10.0.0.250/outlets.htm"][COLOR=darkred]http://10.0.0.250/outlets.htm[/COLOR][/URL]
[COLOR=darkred]User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)[/COLOR]
[COLOR=darkred]Host: 10.0.0.250[/COLOR]
[COLOR=darkred]Content-Length: 140[/COLOR]
[COLOR=darkred]Expect: 100-continue[/COLOR]
[COLOR=darkred]Connection: Keep-Alive[/COLOR]
 
[COLOR=blue]HTTP/1.1 100 Continue[/COLOR]

I should get something like this:
VB.NET:
[COLOR=darkred]POST /Forms/outlets2 HTTP/1.1[/COLOR]
[COLOR=darkred]Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*[/COLOR]
[COLOR=darkred]Referer: [/COLOR][URL="http://10.0.0.250/outlets.htm"][COLOR=darkred]http://10.0.0.250/outlets.htm[/COLOR][/URL]
[COLOR=darkred]Accept-Language: nl-be[/COLOR]
[COLOR=darkred]Content-Type: application/x-www-form-urlencoded[/COLOR]
[COLOR=darkred]Accept-Encoding: gzip, deflate[/COLOR]
[COLOR=darkred]User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)[/COLOR]
[COLOR=darkred]Host: 10.0.0.250[/COLOR]
[COLOR=darkred]Content-Length: 140[/COLOR]
[COLOR=darkred]Connection: Keep-Alive[/COLOR]
[COLOR=darkred]Cache-Control: no-cache[/COLOR]
[COLOR=darkred]Authorization: Basic [Base64 string][/COLOR]
 
[COLOR=darkred]HX=hr&HX2=hr&OutCtl=65000000&OutCtl=c9000000&OutCtl=2d010000&OutCtl=91010000&OutCtl=f5010000&OutCtl=59020000&OutCtl=bd020000&OutCtl=21030000[/COLOR]
 
[COLOR=blue]HTTP/1.1 303 See Other[/COLOR]
[COLOR=blue]Location: [/COLOR][URL="http://10.0.0.250/outlets.htm"][COLOR=blue]http://10.0.0.250/outlets.htm[/COLOR][/URL]
[COLOR=blue]Content-Length: 0[/COLOR]
[COLOR=blue]Server: Allegro-Software-RomPager/3.10[/COLOR]

Does anyone know how I can solve this?

Thanks in advance,
Stijn DP
 
Any luck?

I'm trying to automate out APC master switches as well but haven't had much luck. My approach was to use the HTTPWebRequest and HTTPWebResponse classes but I keep running into an authentication issue when using the NetworkCredential object. It seems to work for the base url, but not for the actual outlet control url. Have you had any luck?
 
Back
Top