我有一个Ruby-On-Rails应用程序,我试图使用Mechanize连接到Dwolla
agent = Mechanize.new
agent.keep_alive = false
agent.log = Logger.new $stderr
agent.agent.http.debug_output = $stderr
ajax_headers = { 'X-Requested-With' => 'XMLHttpRequest', 'Content-Type' => 'application/json; charset=utf-8', 'Accept' => 'application/json, text/javascript, */*'}
response = agent.post( "https://www.dwolla.com/oauth/rest/tes...", query_string.to_json, ajax_headers)
我得到的响应是:
Conn close because of error Connection reset by peer
这些是我要发送的参数:
{"password":"Password1","confirm_password":"Password1","pin":"1234","firstName":"firstName","lastName":"lastName","address":"address","address2":null,"city":"Troy","state":"NY","zip":"12180","phone":"111-123-4567","dateOfBirth":"10/15/1970","type":"Personal","organization":null,"ein":null,"acceptTerms":true,"client_id":"foo","client_secret":bar"}"
记录如下:
Net::HTTP::Post: /oauth/rest/testapi/register
request-header: accept => application/json, text/javascript, */*
request-header: user-agent => Mechanize/2.5.1 Ruby/1.9.2p290 (http://github.com/tenderlove/mechanize/)
request-header: connection => close
request-header: accept-encoding => gzip,deflate,identity
request-header: accept-charset => ISO-8859-1,utf-8;q=0.7,*;q=0.7
request-header: accept-language => en-us,en;q=0.5
request-header: host => www.dwolla.com
request-header: content-type => application/json; charset=utf-8
request-header: content-length => 444
opening connection to www.dwolla.com...
opened
<- "POST /oauth/rest/testapi/register HTTP/1.1rnAccept: application/json, text/javascript, */*rnUser-Agent: Mechanize/2.5.1 Ruby/1.9.2p290 (http://github.com/tenderlove/mechanize/)rnConnection: closernAccept-Encoding: gzip,deflate,identityrnAccept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7rnAccept-Language: en-us,en;q=0.5rnHost: www.dwolla.comrnContent-Type: application/json; charset=utf-8rnContent-Length: 444rnrn"
<- "{"password":"Password1","confirm_password":"Password1","pin":"1234","firstName":"firstName","lastName":"lastName","address":"address","address2":null,"city":"Cohoes","state":"NY","zip":"12047","phone":"111-123-4567","dateOfBirth":"9/13/1973","type":"Personal","organization":null,"ein":null,"acceptTerms":true,"client_id":"foo","client_secret":"bar"}"
Conn close because of error Connection reset by peer
任何帮助都将非常感激!
我认为您使用的是旧的[不支持的]端点。尝试从URL中删除"/testapi"部分…无论如何,该方法的开发文档还包括一个内联控制台,可以帮助您开始使用该方法:https://developers.dwolla.com/dev/docs/register/register