I have a delphi program calling a python rest service.
The python rest service looks like :
@app.route('/flagger/api/v1.0/stem', methods=['GET'])
def stem_request():
print request.json
if not request.json or u'text' not in request.json:
bad_request('no "text" field given')
text = request.json['text']
return jsonify(stemmed=stem(text)), 200
When i do a curl request to that service i get the answer:
C:\Program Files\Curl>curl -i -H "Content-Type: application/json" -X GET -d "{\"text\":\"hij geeft mij appels\"}" h
ttp://192.168.99.100:5000/flagger/api/v1.0/stem
HTTP/1.0 200 OK
Content-Type: application/json
Content-Length: 30
Server: Werkzeug/0.11.3 Python/2.7.10
Date: Thu, 28 Jan 2016 13:17:36 GMT
{
"stemmed": "geeft appel"
}
In my delphi XE7/Pro program i have a Restclient, Restrequest and Restresponse component.
All components have contentype=application/json
restrequest.method=rmGet
to the Restrequest i added a parameter with :
contenttype=ctapplication_json
kind=pkrequestbody
name=text
value=hij geeft mij appels.
The request is started with the following code:
MemoContent.Lines.Add('Start...');
RESTClient1.BaseURL:='http://192.168.99.100:5000/flagger/api/v1.0/stem';
MemoContent.Lines.Add('Request Params.Name= '+RESTRequest1.Params.Items[0].Name);
MemoContent.Lines.Add('Request Params.Value= '+RESTRequest1.Params.Items[0].Value);
RESTRequest1.Execute;
MemoContent.Lines.Add('Status= '+RESTResponse1.StatusText);
MemoContent.Lines.Add('Content= '+RESTResponse1.content);
MemoContent.Lines.Add('FullRequestURI= '+RESTResponse1.FullRequestURI);
MemoContent.Lines.Add('BaseURL= '+RESTClient1.BaseURL);
jValue:=RESTResponse1.JSONValue;
MemoContent.Lines.Add('Response Json= '+jValue.tostring);
MemoContent.Lines.Add('Statustext= '+RESTResponse1.StatusText);
the request is executed but i always get a bad request answer:
Start...
Request Params.Name= text
Request Params.Value= dit is een test
Status= HTTP/1.0 400 BAD REQUEST
Content= {
"error": "bad request"
}
FullRequestURI= http://192.168.99.100:5000/flagger/api/v1.0/stem
BaseURL= http://192.168.99.100:5000/flagger/api/v1.0/stem
Response Json= {"error":"bad request"}
Statustext= HTTP/1.0 400 BAD REQUEST
Anyone has an idea what's wrong here ?
I can't make it work with the rest debugger either but it works with CURL and other rest clients
Thanks.