本文介绍了https://api.imgur.com/3/image的Http失败响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将基数为64的编码图像上传到imgur,并且它始终失败,并显示错误消息 https://api.imgur.com/3/image的Http错误响应:403 OK
.我该如何解决?
I am trying to upload a base 64 encoded image to imgur and it keeps failing with the error message Http failure response for https://api.imgur.com/3/image: 403 OK
. How can I resolve it?
@Injectable()
export class ImgurService {
private readonly IMGUR_UPLOAD_URL = 'https://api.imgur.com/3/image';
private readonly IMGUR_API_KEY = '<api-key-xxxx>';
constructor(
private logger: NGXLogger,
private http: HttpClient
) {
}
upload(b64Image: any) {
this.logger.debug('Handling file input');
this.logger.debug(image);
this.logger.debug(`Uploading picture to ${this.IMGUR_UPLOAD_URL}`);
const httpOptions = {
headers: new HttpHeaders ({
'Authorization': `Bearer ${this.IMGUR_API_KEY}`,
}),
};
const formData = new FormData();
formData.append('image', b64Image);
formData.append('album', 'profile');
return this.http.post<ImgurResponse>(`${this.IMGUR_UPLOAD_URL}`, formData, httpOptions);
}
}
响应:
error:
data: {error: "The access token provided is invalid.", request: "/3/image", method: "POST"}
status: 403
success: false
__proto__: Object
headers: HttpHeaders
lazyInit: ƒ ()
lazyUpdate: null
normalizedNames: Map(0) {}
__proto__: Object
message: "Http failure response for https://api.imgur.com/3/image: 403 OK"
name: "HttpErrorResponse"
ok: false
status: 403
statusText: "OK"
url: "https://api.imgur.com/3/image"
__proto__: HttpResponseBase
推荐答案
您没有正确设置标题:您需要使用set或append,因为对象是不可变的.
you are not setting the headers correctly: you need to use set or append as the object is immutable.
let headers = new HttpHeaders();
headers = headers.set('Authorization', 'Bearer ${this.IMGUR_API_KEY}');
您很有可能在浏览器中看到未发送您的身份验证标头.
Most probably you can see in your browser that your auth header isn't sent.
这篇关于https://api.imgur.com/3/image的Http失败响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!