이것은 편집 된 게시물입니다. http
기본 인증 (예 : 사용자 및 패스) 및 params 개체 (양식에 바인딩)를 사용하여 API 에서이 간단한 요청을 시도하고 있습니다 . 문서를 읽고 여러 게시물을 확인했지만 아무것도 작동하지 않는 것 같습니다. 나는 항상 응답으로 401을 얻습니다 ...
도움을 줄 수 있습니까? (나는 이것에 처음이다)
이것이 내가 가진 것입니다.
import { Component, OnInit } from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {Http, Headers} from '@angular/http';
import {response} from '../../models/response';
import {HttpErrorResponse} from '@angular/common/http';
import {HttpHeaders} from '@angular/common/http';
@Component({
selector: 'app-testing',
templateUrl: './testing.component.html',
styleUrls: ['./testing.component.css']
})
export class TestingComponent implements OnInit {
//OPTIONS
selectedColor:string;
selectedFont:string;
selectedSize:string;
//INTERFACE
results: response;
params = {
"handwriting_id": "8X3WQ4D800B0",
"text": "",
"handwriting_size": "",
"handwriting_color": "",
}
constructor(private http: HttpClient) { }
ngOnInit() {
}
onSubmit(f){
console.log(this.params);
this.http.get<Response>('https://api.handwriting.io/render/png?' + this.params,{
headers: new HttpHeaders().set('7Q0ZBC889M7WRGRM','N6BQK4Z8PZ1HYYT4'),
}).subscribe(data => {
this.results = data['results'];
console.log(this.results);
},(err: HttpErrorResponse) => {
if (err.error instanceof Error) {
console.log('An error occurred:', err.error.message);
} else {
console.log(`Backend returned code ${err.status}, body was: ${err.error}`);
}
});
}
//OPTIONS
changeFont(){
document.getElementById("output-text").style.fontFamily = this.selectedFont;
}
changeColor(){
document.getElementById("output-text").style.color = this.selectedColor;
}
changeSize(){
document.getElementById("output-text").style.fontSize = this.selectedSize;
}
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다