Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Content Type troubles with HTTParty against Rails

require 'HTTParty'
require 'json'

@payload ={
    "email" => "[email protected]",
    "token" => "mytokenstuff",
    "content" => "here is some content",
    "notification_type" => "1",
    "name" => "here is a name",
    "auto_action" => "true"
 }

response = HTTParty.post('http://localhost:3000/api/create.json', :body =>JSON.dump(@payload), :headers => { 'Content-Type' => 'application/json' } )

In my rails controller, the header is coming in ContentType text/html. So obviously my headers param isn't working....

ideas?

like image 921
phil swenson Avatar asked Jul 17 '12 04:07

phil swenson


1 Answers

Try it this way:

HTTParty.post(
  'http://localhost:3000/api/create.json', 
  :body => JSON.dump(@payload), 
  :headers => {
    'Content-Type' => 'application/json', 
  }
)

Try to add Accept too:

:headers => {
  'Content-Type' => 'application/json', 
  'Accept' => 'application/json'
}

Also, check that it is not grabbing the options from a cookie - clean the cookies.

like image 179
Sully Avatar answered Sep 26 '22 10:09

Sully