I'm submitting a web form from a C# Windows program.
The goal is to perform a login by post, after login the webserver automatically redirects to page i want, and gives me the html content as the response i need into a string variable.
I use this code to submit to a form to a normal webserver, namely an Apache to a php page, and works (but not login in, just web form returning a response).
But in this case is a little different. The web server is an Lexmark printer that as is own webpage with reports of the tonners and so on.
If i use the regular DownloadString code with the printer, it works fine, i get the response:
WebClient webClient = new WebClient();
responsefromserver = webClient.DownloadString(URL_PRINTER);
But some printers are protected with password.
So, for those i try this:
NameValueCollection formDataPRINTER = new NameValueCollection();
formDataPRINTER["login_type"] = "password_only";
formDataPRINTER["goto"] = "/cgi-bin/dynamic/printer/config/reports/devicestatistics.html";
formDataPRINTER["accid"] = "13";
formDataPRINTER["password"] = "123456";
responseBytesPRINTER = webClient.UploadValues(URL_PRINTER_LOGIN, "POST", formDataPRINTER);
After the NameValueCollection values are posted to the web page, she should just accept the values login and redirect to "goto" webpage value from the NameValueCollection.
When the debug gets to last line "responseBytesPRINTER = webClient.UploadValues(...
" first i receive this error: "_COMPlusExceptionCode = -532459699" saying "The underlying connection was closed: The connection was closed unexpectedly"
Further, analyzing the error i get more messages like this:
StackTrace " em System.Net.WebClient.UploadValues(Uri address, String method, NameValueCollection data)\r\n em PrinterInfoToRACC.Form1.Form1_Shown(Object sender, EventArgs e) em d:\\Dropbox\\PROJECTOS\\Visual Studio 2013\\Projects\\PrinterInfoToRACC\\PrinterInfoToRACC\\Form1.cs:line 229" string
m_InternalStatus Cannot dereference expression. The pointer is not valid. System.Net.WebExceptionInternalStatus
What am i missing here? :\
Thx in advanced,