English 中文(简体)
POST json 数据和海关负责人
原标题:POST json data and custom headers
  • 时间:2012-04-18 05:30:53
  •  标签:
  • ruby
  • curl

我有以下废墟,试图以同样的方式实施:<条码>。

curl -X POST 
  -H "X-Parse-Application-Id: $APP_ID" 
  -H "X-Parse-REST-API-Key: $KEY" 
  -H "Content-Type: application/json" 
  -d  {"score": 1337, "playerName": "Sean Plott", "cheatMode": false }  
  https://api.parse.com/1/classes/GameScore

这里的废墟法典:

def execute_post
  puts "executing post script.."
  payload ={
    "score" => "1337",
    "playerName" => "Sean Plott", 
    "cheatMode" => "false"

  }.to_json
  headers = {
     X-Parse-Application-Id  => $APP_ID, 
     X-Parse-REST-API-KEY  => $KEY,
     Content-Type  =>  application/json 
  }
  url = "https://" + $DOMAIN + $BASE_URL + $LIST_CLASS
  uri = URI.parse(url)
  puts uri
  puts payload

  puts "***************"
  req = Net::HTTP::Post.new(uri.host, initheader = headers)
  req.body = payload
  response = Net::HTTP.new(uri.host, uri.port).start{|http| http.request(req)}

  puts "Response #{response.code} #{response.message}: #{response.body}"

end

出于某种原因,我错了。 任何关于什么错误的想法?

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/protocol.rb:135:in `sysread : end of file reached (EOFError)
    from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/protocol.rb:135:in `rbuf_fill 
    from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/timeout.rb:62:in `timeout 
    from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/timeout.rb:93:in `timeout 
    from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/protocol.rb:134:in `rbuf_fill 
    from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/protocol.rb:116:in `readuntil 
    from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/protocol.rb:126:in `readline 
    from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:2024:in `read_status_line 
    from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:2013:in `read_new 
    from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:1050:in `request 
    from parse_connect.rb:33:in `execute_post 
    from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/net/http.rb:543:in `start 
    from parse_connect.rb:33:in `execute_post 
    from parse_connect.rb:42
问题回答

尝试这样做:

require  mechanize 
Mechanize.new.post url, data.to_json, headers

if that doesn t work run fiddler and 尝试这样做:

Mechanize.new{|a| a.set_proxy  localhost , 8888}.post url, data.to_json, headers

然后对假肢检查申请。

在你治愈的事例中,你正在使用HTTPS。

您在使用“Net:HTTP”时,需要特别使“HTTPS”能够发挥作用(仅能把https://放在“URL”中)。

http =  Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
response = http.start{|http| http.request(req)}




相关问题
Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

multiple ruby extension modules under one directory

Can sources for discrete ruby extension modules live in the same directory, controlled by the same extconf.rb script? Background: I ve a project with two extension modules, foo.so and bar.so which ...

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

热门标签