Sinatra and XML POST request

Posted by user292815 on Stack Overflow See other posts from Stack Overflow or by user292815
Published on 2010-03-13T05:28:59Z Indexed on 2010/03/13 5:35 UTC
Read the original article Hit count: 844

Filed under:
|
|
|

I don't know is it my mistake or no. So i have that code:

<code>
post '/singin/get_token' do
  content_type  :xml

  puts request.body.read
  puts xmlRequest
  xmlRequest = REXML::Document.new(request.body.read)
...
</code>

And when i post something like that:

<code>
<?xml version="1.0" encoding="utf-16"?><request xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><username>adsfasdf</username></request>
</code>

I receive that in my console:

<code>

127.0.0.1 - - [12/Mar/2010 21:18:20] "POST /singin/get_token HTTP/1.1" 500 105872 0.1339
Iconv::InvalidCharacter - ">":
 /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/1.9.1/rexml/encodings/ICONV.rb:7:in `conv'
 /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/1.9.1/rexml/encodings/ICONV.rb:7:in `decode_iconv'
 /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/1.9.1/rexml/source.rb:58:in `encoding='
 /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/1.9.1/rexml/source.rb:46:in `initialize'
 /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/1.9.1/rexml/source.rb:164:in `initialize'
 /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/1.9.1/rexml/source.rb:17:in `new'
 /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/1.9.1/rexml/source.rb:17:in `create_from'
 /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/1.9.1/rexml/parsers/baseparser.rb:146:in `stream='
 /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/1.9.1/rexml/parsers/baseparser.rb:123:in `initialize'
 /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/1.9.1/rexml/parsers/treeparser.rb:9:in `new'
 /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/1.9.1/rexml/parsers/treeparser.rb:9:in `initialize'
 /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/1.9.1/rexml/document.rb:228:in `new'
 /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/1.9.1/rexml/document.rb:228:in `build'
 /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/1.9.1/rexml/document.rb:43:in `initialize'
 zaiaku-game-server.rb:70:in `new'
 zaiaku-game-server.rb:70:in `block in <main>'
 /Users/andoriyu/.gem/ruby/1.9.1/gems/rack-1.1.0/lib/rack/showexceptions.rb:24:in `call'
 /Users/andoriyu/.gem/ruby/1.9.1/gems/rack-1.1.0/lib/rack/methodoverride.rb:24:in `call'
 /Users/andoriyu/.gem/ruby/1.9.1/gems/rack-1.1.0/lib/rack/commonlogger.rb:18:in `call'
 /Users/andoriyu/.gem/ruby/1.9.1/gems/rack-1.1.0/lib/rack/content_length.rb:13:in `call'
 /Users/andoriyu/.gem/ruby/1.9.1/gems/rack-1.1.0/lib/rack/chunked.rb:15:in `call'
 /Users/andoriyu/.gem/ruby/1.9.1/gems/rack-1.1.0/lib/rack/handler/thin.rb:14:in `run'Iconv::InvalidCharacter: ">"
    /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/1.9.1/rexml/encodings/ICONV.rb:7:in `conv'
    /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/1.9.1/rexml/encodings/ICONV.rb:7:in `decode_iconv'
    /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/1.9.1/rexml/source.rb:58:in `encoding='
    /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/1.9.1/rexml/source.rb:46:in `initialize'
    /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/1.9.1/rexml/source.rb:164:in `initialize'
    /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/1.9.1/rexml/source.rb:17:in `new'
    /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/1.9.1/rexml/source.rb:17:in `create_from'
    /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/1.9.1/rexml/parsers/baseparser.rb:146:in `stream='
    /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/1.9.1/rexml/parsers/baseparser.rb:123:in `initialize'
    /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/1.9.1/rexml/parsers/treeparser.rb:9:in `new'
    /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/1.9.1/rexml/parsers/treeparser.rb:9:in `initialize'
    /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/1.9.1/rexml/document.rb:228:in `new'
    /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/1.9.1/rexml/document.rb:228:in `build'
    /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/1.9.1/rexml/document.rb:43:in `initialize'
    zaiaku-game-server.rb:70:in `new'
    zaiaku-game-server.rb:70:in `block in <main>'
    /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/gems/1.9.1/gems/sinatra-0.9.6/lib/sinatra/base.rb:811:in `call'
    /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/gems/1.9.1/gems/sinatra-0.9.6/lib/sinatra/base.rb:811:in `block in route'
    /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/gems/1.9.1/gems/sinatra-0.9.6/lib/sinatra/base.rb:488:in `instance_eval'
    /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/gems/1.9.1/gems/sinatra-0.9.6/lib/sinatra/base.rb:488:in `route_eval'
    /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/gems/1.9.1/gems/sinatra-0.9.6/lib/sinatra/base.rb:477:in `block (2 levels) in route!'
    /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/gems/1.9.1/gems/sinatra-0.9.6/lib/sinatra/base.rb:474:in `catch'
    /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/gems/1.9.1/gems/sinatra-0.9.6/lib/sinatra/base.rb:474:in `block in route!'
    /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/gems/1.9.1/gems/sinatra-0.9.6/lib/sinatra/base.rb:453:in `each'
    /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/gems/1.9.1/gems/sinatra-0.9.6/lib/sinatra/base.rb:453:in `route!'
    /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/gems/1.9.1/gems/sinatra-0.9.6/lib/sinatra/base.rb:569:in `dispatch!'
    /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/gems/1.9.1/gems/sinatra-0.9.6/lib/sinatra/base.rb:388:in `block in call!'
    /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/gems/1.9.1/gems/sinatra-0.9.6/lib/sinatra/base.rb:536:in `instance_eval'
    /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/gems/1.9.1/gems/sinatra-0.9.6/lib/sinatra/base.rb:536:in `block in invoke'
    /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/gems/1.9.1/gems/sinatra-0.9.6/lib/sinatra/base.rb:536:in `catch'
    /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/gems/1.9.1/gems/sinatra-0.9.6/lib/sinatra/base.rb:536:in `invoke'
    /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/gems/1.9.1/gems/sinatra-0.9.6/lib/sinatra/base.rb:388:in `call!'
    /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/gems/1.9.1/gems/sinatra-0.9.6/lib/sinatra/base.rb:377:in `call'
    /Users/andoriyu/.gem/ruby/1.9.1/gems/rack-1.1.0/lib/rack/showexceptions.rb:24:in `call'
    /Users/andoriyu/.gem/ruby/1.9.1/gems/rack-1.1.0/lib/rack/methodoverride.rb:24:in `call'
    /Users/andoriyu/.gem/ruby/1.9.1/gems/rack-1.1.0/lib/rack/commonlogger.rb:18:in `call'
    /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/gems/1.9.1/gems/sinatra-0.9.6/lib/sinatra/base.rb:928:in `block in call'
    /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/gems/1.9.1/gems/sinatra-0.9.6/lib/sinatra/base.rb:973:in `synchronize'
    /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/gems/1.9.1/gems/sinatra-0.9.6/lib/sinatra/base.rb:928:in `call'
    /Users/andoriyu/.gem/ruby/1.9.1/gems/rack-1.1.0/lib/rack/content_length.rb:13:in `call'
    /Users/andoriyu/.gem/ruby/1.9.1/gems/rack-1.1.0/lib/rack/chunked.rb:15:in `call'
    /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/gems/1.9.1/gems/thin-1.2.7/lib/thin/connection.rb:76:in `block in pre_process'
    /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/gems/1.9.1/gems/thin-1.2.7/lib/thin/connection.rb:74:in `catch'
    /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/gems/1.9.1/gems/thin-1.2.7/lib/thin/connection.rb:74:in `pre_process'
    /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/gems/1.9.1/gems/thin-1.2.7/lib/thin/connection.rb:57:in `process'
    /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/gems/1.9.1/gems/thin-1.2.7/lib/thin/connection.rb:42:in `receive_data'
    /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/gems/1.9.1/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run_machine'
    /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/gems/1.9.1/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run'
    /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/gems/1.9.1/gems/thin-1.2.7/lib/thin/backends/base.rb:57:in `start'
    /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/gems/1.9.1/gems/thin-1.2.7/lib/thin/server.rb:156:in `start'
    /Users/andoriyu/.gem/ruby/1.9.1/gems/rack-1.1.0/lib/rack/handler/thin.rb:14:in `run'
    /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/gems/1.9.1/gems/sinatra-0.9.6/lib/sinatra/base.rb:896:in `run!'
    /Users/andoriyu/.homebrew/Cellar/ruby/1.9.1-p378/lib/ruby/gems/1.9.1/gems/sinatra-0.9.6/lib/sinatra/main.rb:35:in `block in <top (required)>'
!! Unexpected error while processing request: incompatible character encodings: ASCII-8BIT and UTF-8
<code>

© Stack Overflow or respective owner

Related posts about sinatra

Related posts about ruby