0

My current .net code (doesn't work) :

Dim w As New Net.WebClient
Dim values As New Specialized.NameValueCollection
values.Add("username", "toto")
values.Add("password", "totopassword")
w.UploadValues("http://www.webadresse.com", values)
w.DownloadString("http://webadresse.com")

how can i login to this :

<form>
<input type="text" value="username">
<input type="text" value="password">
<a href="#" onclick="javascript: submitFormMaster();">
</form>

And the javascript :

var inputUserName = new Ext.form.TextField({
id : "username",
el : "username",
fieldLabel : stringMaster23,
itemCls : "text_authentification",
labelSeparator : "",
allowBlank : false,
autoCreate : {
    tag : "input",
    type : "text",
    size : "18",
    autocomplete : "on",
    maxlength : "50"
}
});
var inputPassword = new Ext.form.TextField({
id : "password",
el : "password",
fieldLabel : stringMaster24,
itemCls : "text_authentification",
labelSeparator : "",
allowBlank : false,
autoCreate : {
    tag : "input",
    type : "password",
    size : "18",
    autocomplete : "on",
    maxlength : "20"
}
});
var radioGroupPrice = new Ext.form.RadioGroup({
id : "GroupPrice",
vertical : true,
items : [ {
    name : "displayPrice",
    boxLabel : stringMaster25,
    itemCls : "text_radio_price",
    inputValue : "false"
}, {
    name : "displayPrice",
    boxLabel : stringMaster26,
    itemCls : "text_radio_price",
    inputValue : "true",
    checked : true
} ]
});
var renderSubmit = new Ext.form.Label(
    {
        id : "RenderSubmit",
        name : "RenderSubmit",
        html : '<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td align="right" valign="middle"><a href="/ecran/password_lost.asp" class="text_link">'
                + stringMaster27
                + '&nbsp;?</a></td><td>&nbsp;</td><td width="43" align="center" valign="middle"><a href="#" onclick="javascript: submitFormMaster();"><img src="'
                + urlBtnOK
                + '" width="43" height="19" title="'
                + stringMaster29
                + '" alt="'
                + stringMaster29
                + '" border="0" /></a></td></tr></table>'
    });
var formMaster = new Ext.form.FormPanel({
id : "FAuthentication",
title : "",
baseCls : "base-cls-override",
cls : "form_authentication_bis",
standardSubmit : true,
frame : true,
width : 210,
labelWidth : 1,
defaultType : "textfield",
items : [ inputUserName, inputPassword, {
    xtype : "fieldset",
    autoHeight : true,
    border : false,
    style : "padding: 0px 0px 0px 0px",
    layout : "column",
    items : [ radioGroupPrice ]
}, renderSubmit ],
keys : [ {
    key : Ext.EventObject.ENTER,
    fn : submitFormMaster
} ],
listeners : {
    afterrender : function() {
        loadFormData();
    }
}
});
function submitFormMaster() {
if (formMaster.getForm().isValid()) {
    if (!formMaster.getForm().getEl().isMasked()) {
        formMaster.getForm().getEl().dom.method = "POST";
        formMaster.getForm().getEl().dom.action = applicationPath
                + currentCulture + "/Authentication";
        formMaster.getForm().submit();
    }
    formMaster.getForm().getEl().mask(stringMaster37);
}
}
function loadFormData() {
if (warnPopupMaster != "") {
    Ext.Msg.alert(stringMaster29Bis, warnPopupMaster);
}
}
Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = "side";
Ext.onReady(function() {
formMaster.render("AuthenticationForm");
Ext.getCmp("username").focus("", 10);
});

2 Answers 2

1

The request is:

Request URL:http://www.innelec.com/Corporate/en/Authentication
Request Method:POST
username:aaaaaaa
password:bbbbbbb
displayPrice:true

If you want to login and than keep your login status you should add the cookies every request, this is a samlpe class to keep the same cookies every request

public class WebClientWithCookies : WebClient
{
    private CookieContainer _container = new CookieContainer();
    protected override WebRequest GetWebRequest(Uri address)
    {
        HttpWebRequest request = base.GetWebRequest(address) as HttpWebRequest;
        if (request != null)
        {
            request.Method = "Post";
            request.CookieContainer = _container;
        }
        return request;
    }
}

WebClientWithCookies client = new WebClientWithCookies();
client.Headers[HttpRequestHeader.UserAgent] = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31";
client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
client.Encoding = System.Text.Encoding.UTF8;
var result = client.UploadString("http://www.innelec.com/Corporate/en/Authentication", "POST", "username=aaaaaaa&password=bbbbbbb&displayPrice=true");
Sign up to request clarification or add additional context in comments.

Comments

0

you have to send the request to

applicationPath + currentCulture + "/Authentication"

http://www.webadresse.com/en/Authentication

2 Comments

otherwise you can use firebug (or chrome developer tools) and see how request is made from that website
Thanks for help, i give you the real site : www.innelec.com

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.