I'm having trouble posting json data to a webservice using the ansynchronous http network.request call. Seems like the content-type of the body is always "application/x-www-form-urlencoded" regardless of how I try to set the header. I also tried setting the headers on a GET request with no luck.
The documentation on how to pass the parameters is a little ambiguous with regards to params/headers/body. Other than the headers the code below works.
I'm testing in the Corona simulator, build 268.
An http packet sniffer shows the same result as the test webservice.
A sinatra webservice to see what's posted:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | require 'rubygems' require 'sinatra' require 'json' post '/json' do puts "testing json post" print "path_info: "; puts request.path_info print "content_length: "; puts request.content_length print "media_type: "; puts request.media_type print "params.inspect: "; puts params.inspect request.body.rewind # in case someone already read it data = JSON.parse(request.body.read.to_s) print "data.inspect: "; puts data.inspect puts "done." "<html>Your response</html>" end |
Tested on the iphone 4 with the same result - just to rule out that it's not the simulator.
u can't do local host on the device
c