1
我有一個android應用程序將數據導出到rails服務器。當我使用Rails 3時,一切都很好,很有用。但在軌道4的服務器接收,而不是內容的只有以下參數:Rails 4沒有收到http發佈內容,但在Rails 3中工作
{"action"=>"export", "controller"=>"trainings"}
內容由以下發送:
HttpPost httpPost = new HttpPost(link);
String xmlFile = createXml(locationList);
StringEntity entity = new StringEntity(xmlFile, "UTF-8");
httpPost.setEntity(entity);
httpPost.addHeader("Content-Type", "application/xml");
httpClient.execute(httpPost);
並收到由滑軌用下面的代碼:
begin
if !params[:training].nil? && !params[:training][:location].nil? && !params[:training][:datetime].nil?
locations = params[:training][:location]
if locations.count > 0
training = Training.create! created_at: Time.at((params[:training][:datetime].to_i/1000))
locations.each do |xml_location|
if !xml_location["latitude"].nil? && !xml_location["longitude"].nil?
Location.create! latitude: xml_location["latitude"], longitude: xml_location["longitude"], training_id: training.id
end
end
end
end
rescue TimeoutError => e
end
身體的一個例子是以下xml:
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
<training>
<datetime>1409332572032</datetime>
<location>
<longitude>-122.084095</longitude>
<latitude>37.422005</latitude>
</location>
<location>
<longitude>-122.084095</longitude>
<latitude>47.422005000000006</latitude>
</location>
<location>
<longitude>-132.08409333333333</longitude>
<latitude>47.422005000000006</latitude>
</location>
<location>
<longitude>-142.08409333333333</longitude>
<latitude>47.422005000000006</latitude>
</location>
</training>
儘管我搜索了Rails 3到4的變化,但我找不到任何可能導致此行爲更改的內容。
試圖以應用解決方案只是引發以下錯誤: 開始發表於2014年8月30日14時17分32秒+0200 處理「/導出」爲127.0.0.1通過TrainingsController#導出爲HTML 完成400 Bad Request in 0ms ActionController :: ParameterMissing(param丟失或者值爲空:訓練): app/controllers/trainings_controller.rb:57:in'training_params' app/controllers/trainings_controller.rb:21:in 'export' – flp 2014-08-30 12:18:39
我可以看到POST數據的樣子嗎?看起來你沒有發佈「訓練」參數? – mask8 2014-08-30 19:02:23
我看起來像rails現在正在刪除http post的數據,因爲在Rails 3中它沒有問題。帖子數據是:{「action」=>「導出」,「控制器」=>「培訓」},我用training_params.inspect得到它,training_params是params.permit! – flp 2014-08-30 22:08:00