开发者

How to authenticate my form using javascript

there

i need to authenticate before request to the url, if i use XMLHTTPRequest, things go fine

var xmlHttp = ...//some code goes here
xmlHttp.Open('POST','http://www.somesite.com/',false,userID,password);
xmlHttp.Send(null);

But if i need to use a form, like below

>var objForm = eval(formString);
>objForm.target='demoFrame'; //where demoFrame is an iFrame in another page
>objForm开发者_如何转开发.action='http://www.somesite.com/';
>objForm.username.value=userID;
>objForm.password.value=password;
>objForm.method='post';
>objForm.submit();

But seems that the objForm cannot use "username" & "password" as the input for authentication, since i keep receiving "authentication failed" message from the host site

Any idea?

Thanks


I assume that the other site is using HTTP Basic authentication.

Set the action to 'http://' + userId + ':' + password + '@www.somesite.com/'

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜