问题描述
我正在使用Dialgflow V1机器人.我真的受到这个存储库的启发: https://github.com/mlabouardy/dialogflow-angular5
I'm working on a dialgflow V1 bot.I'm really inspired by this repository : https://github.com/mlabouardy/dialogflow-angular5
我的dialogflow服务出现问题.我无法发布带有特殊字符的查询.
I have an issue in my dialogflow service.I can't post query with special characters.
这是我的diaogflow服务的工作方式,但是当我通过查询时,它是utf-8的代码,它破坏了dialogflow:
here is my diaogflow service working but when i pass my query it is code to utf-8 which broke dialogflow :
import { Injectable } from '@angular/core';
import { Http, Headers } from '@angular/http';
import 'rxjs/Rx'
import { environment } from '../../environments/environment';
@Injectable()
export class DialogflowService {
private baseURL: string = "https://api.dialogflow.com/v1/query?v=20170712";
private token: string = environment.dialogFlowToken;
constructor(private http: Http){}
public getResponse(query: string){
let data = {
query : query,
lang: 'fr',
sessionId: '12345'
}
return this.http
.post(`${this.baseURL}`, data, {headers: this.getHeaders()})
.map(res => {
return res.json()
})
}
public getHeaders(){
let headers = new Headers();
headers.append('Authorization', `Bearer ${this.token}`);
return headers;
}
}
我尝试使用:
encode_utf8(s) {
return unescape(encodeURIComponent(s));
}
decode_utf8(s) {
return decodeURIComponent(escape(s));
}
但这没用
您有建议吗?非常感谢.罗曼(Romain)
Do you have a suggestion ?Thanks a lot.Romain
推荐答案
尝试使用其他标头强制使用它,看看是否可行.
try to force it with additional header and see if that works.
{'Content-Type':'application/json;charset = UTF-8'}
{'Content-Type' : 'application/json; charset=UTF-8'}
这篇关于无法将特殊字符发布到dialogflow查询中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!