POST method in RestClient using Rails


#1

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/companymaster/Add",{“CompanyMaster”:{“Address1”:“RajaStreet”,“BussinessProfile”:"lll”,
“City”:“statee”,“CompanyID”:24,“CompanyName”:“RamuMetall”,
“CreatedBy”:138,“Email”:“removed_email_address@domain.invalid”,“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.


#2

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/companymaster/Add”,
{“CompanyMaster”:
{“Address1”:“Ganapathy”,“Address2”:“Coimbatore”,“BussinessProfile”:“null”,
“City”:“null”,“CompanyID”:25,“CompanyName”:“Priya
agency”,“CreatedBy”:138,“CreatedDate”:“19-06-2015
11:01:41”,“Email”:“removed_email_address@domain.invalid”,“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”