我正在尝试向此地址https://unicom24.ru/api/partners/requests/v1/locality/
发出请求我正在使用httparty gem。我需要使用基本的http Auth。 我拿到了我的身份验证密钥并按照这样的要求提出:
headers = {'Authorization' => 'Basic bMyAuthKeydv4K'}
HTTParty.get(
"https://unicom24.ru/api/partners/requests/v1/locality/",
:headers => headers
)
我得到了回复:
@response=#<Net::HTTPUnauthorized 401 Unauthorized readbody=true>
不允许的电子邮件或密码。 我该怎么办?
答案 0 :(得分:2)
auth = {username: 'user', password: 'pass'}
result = HTTParty.get(
"https://unicom24.ru/api/partners/requests/v1/locality/",
basic_auth: auth
)
基本身份验证
'use strict';
class ExtendableError extends Error {
constructor(message) {
super();
this.message = message;
this.stack = (new Error()).stack;
this.name = this.constructor.name;
}
}
class MyError extends ExtendableError {
constructor(message) {
super(message);
}
}
try {
throw new Error('Oops!');
} catch (err) {
console.log(err);
}
try {
throw new MyError('Oops!');
} catch (err) {
console.log(err);
}