How to fill forms and submit with Webclient in C# -
Hey, I'm using libraries in WebClient, HttpResponse and HttpRequest C #, so bare with me, if reading my question Is confusing in
I need to build a WinForm based on C #, which can open a URL, which is protected with the original authorization. I did this with adding it to the header, like:
using (webclient wc = new webclient ()) {wc.Headers.Add (HttpRequestHeader.Authorization, "Basic" + Convert ToBase64String (Encoding. ASCII.GetBytes (username: "+": "+ password));} So rent, very good! Now I want to fill out a form with a number, And I get the source code from the site, and it shows that the name is "number." So I write this:
NameAllCollection format Ta = new nameVollection (); FormData ["number"] = number byte [] feedbackbay = wc.UploadValues (Thural, "Post", FormData); String Response = Encoding; ASCII.GetString (responseBytes); TextBox_HTML.Text = Response; But how do I submit it? I would like to get my "result-find" ...
Here is a simple example:
var strId = UserId_TextBox.Text; Var strName = Name_TextBox.Text; Var encoding = new ASCIIEncoding (); Var postData = "userid =" + strId; PostData + = ("& amp; Username =" + strName); Byte [] Data = Encoding Getbytes (postdata); Var myRequest = (HttpWebRequest) WebRequest.Create ("http: //localhost/MyIdentity/Default.aspx"); MyRequest.method = "Post"; MyRequest.ContentType = "application / x-www form-urlencoded"; MyRequest.ContentLength = data.Length; Var newstream = myRequest.GetRequestStream (); NewStream.Write (data, 0, data.Length); NewStream.Close (); Var response = myRequest.GetResponse (); Var reactionflow = feedback Gateresonsstream (); Var reactor = new streamrider (responses); Var result = responseReader.ReadToEnd (); ResponseReader.Close (); Response.Close ();
Comments
Post a Comment