Forum: Ruby on Rails POST method in RestClient using Rails

C4c660a54a9c47b21b8ba621f2d71633?d=identicon&s=25 Poombavai Sivamani (poombavai)
on 2016-09-06 10:47
I am trying to post values using RestClient. It always shows the
following error.

    RestClient::BadRequest (400 Bad Request):

Tried all the answers in SO. Nothing helped. This is my code.

response = RestClient.post
"http://192.72.114.66/WDSTEST_WS/WDS_SERVICE.svc/co...,
"City":"statee","CompanyID":24,"CompanyName":"RamuMetall",
"CreatedBy":138,"Email":"abcd@gmail.com","IsActive":true,
"LandLine":"435435","MobileNumber1":"8787871221","ModifiedBy":138,
"PinCode":0,"Remarks":"null","State":"null","TonnageKM":"0",
"TotalInsurableGoodValueForPreviousYear":0.00,
"TotalInsurableGoodValuePerYear":0.00,
"TotalTransportationCostForPreviousYear":0.00,
"TotalTransportationCostPerYear":0.00,"TotalTransportedWeightPerYear":0.00,
"Website":"null"}},
headers: {"Content-Type" => "application/json"}

This is just a dummy data. Please help. Thanks in advance.
C4c660a54a9c47b21b8ba621f2d71633?d=identicon&s=25 Poombavai Sivamani (poombavai)
on 2016-09-06 12:16
Finally, I solved it. There was a mistake in format. The correct format
is,


response = RestClient.post
"http://192.72.114.66/WDSTEST_WS/WDS_SERVICE.svc/co...,
{"CompanyMaster":
{"Address1":"Ganapathy","Address2":"Coimbatore","BussinessProfile":"null",
"City":"null","CompanyID":25,"CompanyName":"Priya
agency","CreatedBy":138,"CreatedDate":"19-06-2015
11:01:41","Email":"poombavai@gmail.com","IsActive":true,
"LandLine":"06654-3422412","MobileNumber1":"9568678567",
"ModifiedBy":138,"PinCode":643434,"Remarks":"null",
"TonnageKM":"122","Website":"www.poombavai.com"}}.to_json,
:content_type => "application/json"
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.