简体   繁体   中英

set parameter for textbox in http request in c#

I want to login through some site with my C# code and login page has a username and a password textbox with ids as below

<input name="login:password" class="ui-inputfield ui-password ui-widget ui-state-default ui-corner-all" id="login:password" role="textbox" aria-disabled="false" aria-readonly="false" aria-multiline="false" type="password" size="40" autocomplete="off">

and my c# code for getting response text is ..

string responseText = httpRequestFactory.Create(url)
                .SetKeepAlive(false)
                .SetMethod(HttpMethods.Post)
                .SetContentType(ContentTypes.MultiPartFormDataWithBoundary)
                .SetReferer(url)
                .AddParameter("login:loginName", username)
                .AddParameter("login:password", password)
                .GetResponse()
                .GetResponseAsString();

How can I login successfully with changes in my C# code?

Please help me.

Your input is not a server control. To do what you are trying to do would require you to use runat="server" but then your control names would need to be set to static. I would consider using ajax instead to send the inputs values to the server and handle your login there. Then you are really not concerned with the input's name, just the value you are passing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM