android에서 http가있는 xml 파일을 레일즈 서버로 보내려고합니다.Android에서 레일 서버로 HTTP 요청 보내기
내 안드로이드 송신 코드 : I 내보내기 링크를 수신하는 제어 방법을 만든 레일에서
String link = "http://10.0.2.2:3000/export";
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(link);
try {
String xmlFile = createXml(locationList);
StringEntity entity = new StringEntity(xmlFile, "UTF-8");
httppost.setEntity(entity);
httppost.addHeader("Content-Type", "application/xml");
HttpResponse response = httpclient.execute(httppost);
Log.d("response reason phrase", ""
+ response.getStatusLine().getReasonPhrase());
Log.d("response content", ""
+ response.getStatusLine().getStatusCode());
} catch (ClientProtocolException e) {
Log.d("exception", e.getMessage());
} catch (IOException e) {
Log.d("exception", e.getMessage());
}
:
def export
begin
result = Net::HTTP.get(URI.parse("http://localhost:3000/export"))
MyLog.debug "#{result}"
xml_doc = Nokogiri::XML(result)
locations = xml_doc.xpath("//location")
if locations.count > 0
training = Training.create!
locations.each do |xml_location|
location = Location.new
location.latitude = xml_location.xpath("latitude").text
location.longitude = xml_location.xpath("longitude").text
location.training_id = training.id
location.save!
end
end
# end
rescue TimeoutError => e
MyLog.debug "timeout #{e}"
end
end
그리고이 export.html을 만들 수 밖에 없었다.
:Nothing to see
내 routes.rb이 포함되어 다음이 포함 ERB, 이 후
Started POST "/export" for 127.0.0.1 at 2013-01-15 22:47:59 +0100
Connecting to database specified by database.yml
Processing by TrainingsController#export as HTML
Parameters: {"training"=>{"location"=>[{"longitude"=>"60.0",
"latitude"=>"60.0"}, {"longitude"=>"59.9999", "latitude"=>"60.0"},
{"longitude"=>"59.99995", "latitude"=>"59.9999"}]}}
WARNING: Can't verify CSRF token authenticity
Rendered trainings/export.html.erb within layouts/application (25.0ms)
Completed 200 OK in 61633ms (Views: 576.0ms | ActiveRecord: 0.0ms)
내 서버에 액세스 할 수 없습니다 더 내가 볼 것이다 : 나는 서버에 내 응용 프로그램과 함께 지금은 요청을 보내는 경우 0
match 'export' => 'Trainings#export', as: "export", :via => [:get, :post]
는하지만, 나는 내에서는 cmd 다음을 참조 콘솔 항상 다음
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2013-01-15 22:53:00 +0100
Served asset /jquery.js - 200 OK (76ms)
[2013-01-15 22:53:00] ERROR Errno::ECONNABORTED: Eine bestehende Verbindung wurd
e softwaregesteuertdurch den Hostcomputer abgebrochen.
C:/Ruby/Ruby193/lib/ruby/1.9.1/webrick/httpresponse.rb:396:in `write'
C:/Ruby/Ruby193/lib/ruby/1.9.1/webrick/httpresponse.rb:396:in `<<'
C:/Ruby/Ruby193/lib/ruby/1.9.1/webrick/httpresponse.rb:396:in `_write_data'
C:/Ruby/Ruby193/lib/ruby/1.9.1/webrick/httpresponse.rb:368:in `send_body_string'
C:/Ruby/Ruby193/lib/ruby/1.9.1/webrick/httpresponse.rb:249:in `send_body'
C:/Ruby/Ruby193/lib/ruby/1.9.1/webrick/httpresponse.rb:152:in `send_response'
C:/Ruby/Ruby193/lib/ruby/1.9.1/webrick/httpserver.rb:110:in `run'
C:/Ruby/Ruby193/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
나는 방법에서 생성 된 XML 파일을 복사하여 그것을 테스트했기 때문에 내 XML 파싱 다행히, 노력, 그러나 희망 당신이 내 문제를 이해하기 위해 내 도움이 될 수 있습니다 : . 나는 많은 시간을 수색했지만, 내 문제를 해결하는 데 도움이되는 어떤 것을하지 않았다.