JavaScript 中的 Rest api 身份验证
我正在尝试将 REST api 与 JavaScript 结合使用,但似乎无法让它工作。我有一个 Perl 等效项,如下所示:
my $req = HTTP::Request->new(POST => 'https://someurl');
$req->content_type('application/xml');
$req->headers(Accept => 'application/xml; charset=utf-8');
$req->authorization_basic('username','password');
$req->content($body);
这是请求。我如何在 JavaScript 中执行此操作,我在网上查找并找不到任何明显的语法。
I am trying to use a REST api with JavaScript and can't seem to get it to work. I have a Perl equivalent which is as follows:
my $req = HTTP::Request->new(POST => 'https://someurl');
$req->content_type('application/xml');
$req->headers(Accept => 'application/xml; charset=utf-8');
$req->authorization_basic('username','password');
$req->content($body);
This is the request. How do I do this in JavaScript, I looked online and couldn't find anything obvious for syntax.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它对于用户 jquery 框架和进行 ajax 调用很有用
It will useful to user jquery framework and make ajax call like
您将需要使用
.ajax
方法。请参阅http://dothow.blogspot.com/2009/ 05/http-basic-authentication-with-jquery.html 有关 jquery 基本授权的示例。You will need to use the
.ajax
method. See http://dothow.blogspot.com/2009/05/http-basic-authentication-with-jquery.html for an example of basic authorization from jquery.