【问题标题】:POST method in RestClient using Rails使用 Rails 的 RestClient 中的 POST 方法
【发布时间】:2023-03-16 21:56:01
【问题描述】:

我正在尝试使用 RestClient 发布值。它总是显示以下错误。

RestClient::BadRequest(400 错误请求):

尝试了 SO 中的所有答案。没有任何帮助。这是我的代码。

response = RestClient.post "http://192.72.114.66/WDSTEST_WS/WDS_SERVICE.svc/companymaster/Add",{"CompanyMaster":{"Address1":"Raja Street cbe","BussinessProfile":"lll","City":"statee","CompanyID": 24,"CompanyName":"Ramu Metall","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"}},标题:{"Content-Type" => "application/json"}

这只是一个虚拟数据。 请帮忙。提前致谢。

【问题讨论】:

    标签: ruby-on-rails rest-client


    【解决方案1】:

    最后,我解决了。格式有误。正确的格式是,

    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":"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"
    

    【讨论】:

    • 很高兴你知道了!如果您将此答案标记为“已接受”,它将让人们知道您已准备就绪。
    猜你喜欢
    • 2016-03-26
    • 1970-01-01
    • 2018-03-09
    • 1970-01-01
    • 1970-01-01
    • 2015-01-04
    • 2011-08-14
    • 2019-12-28
    • 2017-03-05
    相关资源
    最近更新 更多