472,127 Members | 1,445 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,127 software developers and data experts.

WebClient Problem

Hi,

I've got a little problem with the WebClient, I always get a failure while
debugging this code:

private void menuItem2_Click(object sender, System.EventArgs e)

{

NameValueCollection values = new NameValueCollection();

values.Add("pptpdisconnect","true");

string got =
UploadValuesToSecureWebsite("http://192.168.0.1/","admin","*******","post",v
alues);

}

public string UploadValuesToSecureWebsite(string URL, string Username,
string Password, string Method, NameValueCollection values)

{

WebClient myWebClient = new WebClient();

NetworkCredential trust = new NetworkCredential(Username,Password);

myWebClient.Credentials = trust;

byte[] Response = myWebClient.UploadValues(URL, Method, values);

string result = Encoding.ASCII.GetString(Response);

return result;

}

Regards, Max - I hope my English was understandable, or even good ;-)
PS: Here, the details about the failure:

at System.Net.ConnectStream.BeginRead(Byte[] buffer, Int32 offset, Int32
size, AsyncCallback callback, Object state)
at System.Net.ConnectStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.WebClient.ResponseAsBytes(WebResponse response)
at System.Net.WebClient.UploadValues(String address, String method,
NameValueCollection data)
Nov 16 '05 #1
2 4106
I've worked A LOT with the web client, in fact, have a whole web site
scraping/auto form login/message board setup now.

It appears that the error you are getting is probably caused by the site
disconnecting you as the error is occuring in the 'response' section of the
connect methods.

I don’t know exactly, however, I am going to take a wild guess here.. Are
you sure that the "pptpdisconnect" variable is supposed to be True and not
"on" or blank? And is the server killing the connection because it is seeing
bad data coming across. Seeing that this is a "post" operation, most posted
webpages, using checkboxes, indicate the true, or checked state, with "on"
and not "true".

Try that and see. Also, it would help to know the exact exception that you
were getting... I know I probably have the book of every one you can
possibly get after writing this thing. Break the program when the exception
occurs, print the e.message, as well as the e.innerexception.message if the
innerexception is set.

"Max Gattringer" <ma***********@msn.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi,

I've got a little problem with the WebClient, I always get a failure while
debugging this code:

private void menuItem2_Click(object sender, System.EventArgs e)

{

NameValueCollection values = new NameValueCollection();

values.Add("pptpdisconnect","true");

string got =
UploadValuesToSecureWebsite("http://192.168.0.1/","admin","*******","post",v alues);

}

public string UploadValuesToSecureWebsite(string URL, string Username,
string Password, string Method, NameValueCollection values)

{

WebClient myWebClient = new WebClient();

NetworkCredential trust = new NetworkCredential(Username,Password);

myWebClient.Credentials = trust;

byte[] Response = myWebClient.UploadValues(URL, Method, values);

string result = Encoding.ASCII.GetString(Response);

return result;

}

Regards, Max - I hope my English was understandable, or even good ;-)
PS: Here, the details about the failure:

at System.Net.ConnectStream.BeginRead(Byte[] buffer, Int32 offset, Int32
size, AsyncCallback callback, Object state)
at System.Net.ConnectStream.Read(Byte[] buffer, Int32 offset, Int32 size) at System.Net.WebClient.ResponseAsBytes(WebResponse response)
at System.Net.WebClient.UploadValues(String address, String method,
NameValueCollection data)

Nov 16 '05 #2
Hi, just found my failure: All my methods completely okay, but i always
used http://192.168.0.1, but actually i had to use
192.168.0.1/status.cqi! Shame on me, but at least it works now..
Furthermore there is difference between using
?pptpdisconnect=true/disconnect or whatsover - any value...

Regards, Max
PS: Foolish failure isn't it ;-)

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Helen Abell | last post: by
2 posts views Thread by Gary Short | last post: by
2 posts views Thread by xzzy | last post: by
reply views Thread by Helen | last post: by
3 posts views Thread by Manuel | last post: by
6 posts views Thread by Giovanni | last post: by
4 posts views Thread by Lehel Kovach | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.