我当前的.net代码(不起作用):
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")
我如何登录:
<form>
<input type="text" value="username">
<input type="text" value="password">
<a href="#" onclick="javascript: submitFormMaster();">
</form>
和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
+ ' ?</a></td><td> </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);
});
答案 0 :(得分:1)
请求是:
Request URL:http://www.innelec.com/Corporate/en/Authentication
Request Method:POST
username:aaaaaaa
password:bbbbbbb
displayPrice:true
如果您想登录并保持登录状态,您应该在每次请求时添加cookie,这是一个samlpe类,以便在每次请求时保留相同的cookie
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");
答案 1 :(得分:0)
您必须将请求发送到
applicationPath + currentCulture + "/Authentication"
http://www.webadresse.com/en/Authentication