2017-10-30 3 views
0

API에 전송되는 이러한 동적 값 (매개 변수)이 있으므로 포맷 된 텍스트 (크기 및 색상)를 삽입 한 후 PNG 이미지를 얻을 수 있습니다. 입력 :특수 문자 인코딩 문제 : API GET 요청에서 무시되는 4 개의 매개 변수 중 하나

params = { 
    "handwriting_id": "8X3WQ4D800B0", 
    "text": "", 
    "handwriting_size": "", 
    "handwriting_color": "", 
    } 

첫 번째와 두 번째가 필요하지 않습니다. 내 문제는 마지막 매개 변수 (색상)가 무시되고 있다는 것입니다. 다른 색상은 무시됩니다. 내가 선택한 크기로 텍스트를 작성하지만 컬러가 아닌 텍스트는 항상 검정색으로 표시됩니다. 이것은 revelant HTML입니다 :

<mat-form-field class="block center"> 
    <mat-select placeholder="Choose Color" [(ngModel)]="selectedColor" [(ngModel)]="params.handwriting_color" (change)="changeColor()"> 
     <mat-option value="#FF0000" selected="selected">Red 

     </mat-option> 
     <mat-option value="#8c30ec">Blue 
     </mat-option> 
     <mat-option value="#ec30db">Violet 
     </mat-option> 

    </mat-select> 
    </mat-form-field> 

그리고 이것은 호출로 URL을 사용자 정의 문자열과 그 PARAMS입니다 : 솔직히

const url = 
     `https://api.handwriting.io/render/png?handwriting_id=${this.params.handwriting_id}&text=${this.params.text}&handwriting_size=${this.params.handwriting_size}&handwriting_color=${this.params.handwriting_color}`; 

, 나는 그것을 얻지 않는다; 왜 단지 하나의 매개 변수가 무시되고 있습니까? 어떤 도움이 apreciated 될 것이다

편집 :

params = { 
    "handwriting_id": "8X3WQ4D800B0", 
    "text": "", 
    "handwriting_size": "", 
    "handwriting_color": "", 
    } 
    color = encodeURIComponent(this.params.handwriting_color); 

다음 URL에 전달 :

const url = 
     `https://api.handwriting.io/render/png?handwriting_id=${this.params.handwriting_id}&text=${this.params.text}&handwriting_size=${this.params.handwriting_size}&handwriting_color=${this.color}`; 

하지만 여전히 결과가 없습니다 @Fateh 모하메드 내가이 시도 제안으로

...

답변

1

다음을 사용하십시오.

encodeURIComponent(uri); 

인코딩 특수 문자

+0

당신이있어 오신 것을 환영합니다 :) –

+0

미안 @Fateh 모하메드 해요,하지만 all..I이 시도 후'CONST URI를 =' '은 https : //api.handwriting .io/render/png? handwriting_id = $ {this.params.handwriting_id} & text = $ {this.params.text} & handwriting_size = $ {this.params.handwriting_size} & handwriting_color = $ {this.params.handwriting_color}'; 'const url = encodeURIComponent (uri);'그러나 색상은 여전히 ​​바뀌지 않습니다 ... 내가 뭘 잘못하고 있습니까? – Mellville

+0

ok 색상 변수 만 인코딩하고 모든 uri를 인코딩하지 말고 결국 uri의 인코딩 된 색상을 사용하십시오. encodeURIComponent (params.handwriting_color); –