如何使用jquery传递用户名和密码

发布于 2024-12-01 03:12:49 字数 1009 浏览 3 评论 0原文

我尝试了几个小时,通过查询传递我的用户名和密码。 我找到了不同的答案,例如

$.ajax({        
username: "user",
password: "password",
url: "http://de.wikipedia.org/wiki/S",
type: "GET",
dataType:'json',
success: function() {alert('blub');},
error: function(){alert('nein!');}, });

$.ajax({        
url: "http://de.wikipedia.org/wiki/S",
success: function() {alert('blub');},
error: function(){alert('nein!');},
beforeSend: function(xhr){
xhr.setRequestHeader("Authorization", "Basic c2Nod1bm5zmRlbGbg0K")},    
});

以及

$('#test1').load('http://[email protected]/wiki/S');

更多,但它们都不起作用。 有人可以帮忙吗? 请!!!我绝望了!!!

也许我应该更具体一些。 如果我尝试打开文档,则会收到错误“NetworkError:407 需要代理身份验证 - http://de .wikipedia.org/wiki/S"" 所以我认为用户名和密码传递不正确。

I tried for several hours, to deliver my username and my password with query.
I found different answers like

$.ajax({        
username: "user",
password: "password",
url: "http://de.wikipedia.org/wiki/S",
type: "GET",
dataType:'json',
success: function() {alert('blub');},
error: function(){alert('nein!');}, });

and

$.ajax({        
url: "http://de.wikipedia.org/wiki/S",
success: function() {alert('blub');},
error: function(){alert('nein!');},
beforeSend: function(xhr){
xhr.setRequestHeader("Authorization", "Basic c2Nod1bm5zmRlbGbg0K")},    
});

and

$('#test1').load('http://[email protected]/wiki/S');

and several more, but neither of them is working.
Can anybody help?
Please!!! I´m despaired!!!

Maybe I should be more specific.
If I try to open the document I get the Error ""NetworkError: 407 Proxy Authentication Required - http://de.wikipedia.org/wiki/S""
So I think the username and password isn´t delivered right.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

幸福不弃 2024-12-08 03:12:49

您似乎违反了同源政策:

由于浏览器安全限制,大多数“Ajax”请求都会受到影响
同源政策;
该请求无法成功检索来自不同域、子域或协议的数据。
脚本和JSONP请求不受同源策略限制。

Looks like you have a violation of the same origin policy:

Due to browser security restrictions, most "Ajax" requests are subject
to the same origin policy;
the request can not successfully retrieve data from a different domain, subdomain, or protocol.
Script and JSONP requests are not subject to the same origin policy restrictions.

披肩女神 2024-12-08 03:12:49

为了避免 @jk 提到的 SOP,您可能需要一个服务器端脚本(在您的主机上)来加载外部 url 并将数据返回到您的客户端脚本。

编辑:添加您的评论。

我是一个 .Net 人员,所以我的 PHP 帮助将是有限的。我认为您可以使用 CURL 在 PHP 中使用外部 Web 资源,并且我假设 CURL 可以在帖子中传递凭据。您的 javascript 必须发布到您的 PHP 文件,该文件将发布到 wikipedia 并返回您需要的任何内容给 javascript。

to avoid the SOP that @jk mentioned you would likely need a server side script (on your host) to load the external url and return the data to your client side script.

Edit: to add re your comment.

I'm a .Net guy so my PHP help will be limited. I think you can use CURL to consume external web resources in PHP and I'm assuming that CURL can pass in credentials on a post. Your javascript would have to post to your PHP file, which would post to wikipedia and return whatever you needed to the javascript.

旧街凉风 2024-12-08 03:12:49

尽管我建议您对密码非常小心,并且不要将其存储在可公开访问的 (html/js) 文件中,但我对此有 10 美分的意见。

对于这个维基百科站点,登录是这样发生的:

进行 POST 事务:

http://de.wikipedia.org/w/index.php?title=Spezial:Anmelden&action=submitlogin&type=login&returnto=S

发送以下参数:

  • wpName:blablabla
  • wpPassword:blablabla
  • wpCentralLogin:1
  • wpLoginAttempt:Anmelden
  • wpLoginToken:bignumberthingythatwillprobouslybe Differenteachtime

希望这能让您继续下去。

Although I advice you to be very careful with your password, and not to store it inside a publicly accessible (html/js) file, here's my 10 cents on this.

For this Wikipedia site, a login happens like this:

A POST transaction is made to:

http://de.wikipedia.org/w/index.php?title=Spezial:Anmelden&action=submitlogin&type=login&returnto=S

The following parameters are sent:

  • wpName:blablabla
  • wpPassword:blablabla
  • wpCentralLogin:1
  • wpLoginAttempt:Anmelden
  • wpLoginToken:bignumberthingythatwillprobablybedifferenteachtime

Hope that will get you going.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文