Jump to content
mvanrijnen

TEndpointRequest, can not get body (json)

Recommended Posts

Hello, maybe someone can help me out with the following problem, serverside resource

See following code, i post a request for updating something, serverside can not find body?

 

this is what the post request, posts to the server (captured with fiddler):

 


POST http://pc-pcname:8080/appointments/21140 HTTP/1.1
Connection: Keep-Alive
Content-Type: application/json
Accept: application/json, text/plain; q=0.9, text/html;q=0.8,
Accept-Charset: utf-8, *;q=0.8
User-Agent: Embarcadero RESTClient/1.0
Content-Length: 435
Host: pc-ict1:8080

application/json{"ID":21140,"Description":"blah blah blah" "UpdateState":0}

Server Side:


procedure TAppoinmentResource.PostAppointment(const AContext: TEndpointContext; const ARequest: TEndpointRequest; const AResponse: TEndpointResponse);
var
  jsonobj : TJSONObject;
begin
  if ARequest.Body.TryGetObject(jsonobj) then
  begin

    // do something with the jsonobject
  end;
end;


 

Client Side


procedure TPlannerRestClient.UpdateAppointment(const AAppointment: TPlannerAPIAppointment);
var
  request : TRESTRequest;
  jsonstring : string;
  jsonobject : TJSONObject;
begin
  request := NewRequest(resAppointment, TRESTRequestMethod.rmPOST);
  try
    request.ResourceSuffix := AAppointment.ID.ToString;

 

    // todo fix serialization
    TgoBsonSerializer.Serialize(AAppointment, jsonstring);
    jsonobject := TJSONObject.ParseJSONValue(jsonstring) as TJSONObject;

 

    request.ClearBody;
    request.AddBody(jsonobject);
    request.Execute;
  finally
    jsonobject.Free
    request.Free;
  end;
end;

 

Somebody a hint what i'm doing wrong?

 

Edited by mvanrijnen

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×