WebClient Problem

M

Max Gattringer

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)
 
R

Richard Brown

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.
 
M

Max Gattringer

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 ;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top