Hi Tanja, thanks a lot for your help!
I have solved some problems through your help, so now my rasa server works well when I use post and get request in the shell.
However, if I send the post request through Java language, still, the get request works well but POST can get no response. I used the debug mode and the bug information is:
2019-07-03 15:46:48 DEBUG rasa.server - Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/sanic/request.py", line 149, in load_json
self.parsed_json = loads(self.body)
ValueError: Unexpected character found when decoding 'true'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/rasa/server.py", line 801, in parse
data = emulator.normalise_request_json(request.json)
File "/usr/local/lib/python3.6/site-packages/sanic/request.py", line 143, in json
self.load_json()
File "/usr/local/lib/python3.6/site-packages/sanic/request.py", line 153, in load_json
raise InvalidUsage("Failed when parsing body as json")
sanic.exceptions.InvalidUsage: Failed when parsing body as json
There might be some problems with the entity of post request, but I cannot find it… I wonder if you might have some ideas.
The post and get request codes in Java are shown here:
public static String post(String url, Map<String, Object> params){
HttpClient client = HttpClients.createDefault();
HttpPost post = new HttpPost(url);
post.addHeader("Content-Type","application/json");
//set parameters
List<NameValuePair> list = new ArrayList<NameValuePair>();
for(Entry<String, Object> e : params.entrySet()){
list.add(new BasicNameValuePair(e.getKey(),String.valueOf(e.getValue())));
}
try {
if(list.size() > 0){
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(list,"UTF-8");
post.setEntity(entity);
}
HttpResponse response = client.execute(post);
HttpEntity entity = response.getEntity();
StatusLine statusLine = response.getStatusLine();
if(statusLine.getStatusCode() == HttpStatus.SC_OK){
String content = EntityUtils.toString(entity, "UTF-8");
if(content == null){
content = "";
}
return content;
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return "";
}
public static String get(String url){
HttpClient client = HttpClients.createDefault();
HttpGet get = new HttpGet(url);
get.addHeader("Content-Type","application/json");
try {
HttpResponse response = client.execute(get);
HttpEntity entity = response.getEntity();
StatusLine statusLine = response.getStatusLine();
if(statusLine.getStatusCode() == HttpStatus.SC_OK){
String content = EntityUtils.toString(entity, "UTF-8");
if(content == null){
content = "";
}
return content;
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return "";
}
Thanks!