I am trying to query USPS to get shipping rates in my Rails app.
I am currently fighting Net:HTTP and so I thought I''d ask for some
help.
USPS only accepts GET requests, no POST... So, I have something along the
following lines:
@response_plain = Net::HTTP.get(USPS_SERVER_URL,
"/ShippingAPITest.dll?API=RateV2&XML=#{data}")
''data'' is an XML string we generate elsewhere.
All I am getting back is:
getaddrinfo: No address associated with nodename
Which I am guessing is the response from whatever low-level OS call
implements this network call (?)...
Well, if I print out the string that it''s using:
http://testing.shippingapis.com/ShippingAPITest.dll?API=RateV2&XML=<RateV2Re
quest USERID="xxxxx"><Package
ID="0"><Service>PRIORITY</Service><ZipOrigination>10022</ZipOrigination><Zip
Destination>20008</ZipDestination><Pounds>10</Pounds><Ounces>5</Ounces><Cont
ainer>Flat Rate
Box</Container><Size>REGULAR</Size></Package></RateV2Request>
That URL works. It is the test server USPS URL and returns a response in a
browser...
So, what am I doing wrong? I have been trying variations of this for over an
hour and I''m ready to punch the wall.
> I am trying to query USPS to get shipping rates in my Rails app. > > I am currently fighting Net:HTTP and so I thought I''d ask for some help. > > USPS only accepts GET requests, no POST... So, I have something along the > following lines: > > @response_plain = Net::HTTP.get(USPS_SERVER_URL, > "/ShippingAPITest.dll?API=RateV2&XML=#{data}") > > ''data'' is an XML string we generate elsewhere. > > All I am getting back is: > > getaddrinfo: No address associated with nodename > > Which I am guessing is the response from whatever low-level OS call > implements this network call (?)... > > Well, if I print out the string that it''s using: > > http://testing.shippingapis.com/ShippingAPITest.dll?API=RateV2&XML=<RateV2Re > quest USERID="xxxxx"><Package > ID="0"><Service>PRIORITY</Service><ZipOrigination>10022</ZipOrigination><Zip > Destination>20008</ZipDestination><Pounds>10</Pounds><Ounces>5</Ounces><Cont > ainer>Flat Rate > Box</Container><Size>REGULAR</Size></Package></RateV2Request> > > That URL works. It is the test server USPS URL and returns a response in a > browser... > > So, what am I doing wrong? I have been trying variations of this for over an > hour and I''m ready to punch the wall.Take a look at open-uri... http://stdlib.rubyonrails.org/libdoc/open-uri/rdoc/index.html
Hi,
The code below works for me.
Maybe you want to CGI.escape your XML before making your HTTP request ...
def notifyViaSMS(number, message, api, user, password)
result = nil
message = CGI.escape message
request =
"/http/sendmsg?api_id=#{api}&user=#{user}&password=#{password}&to=#{number}&text=#{message}&from=CoreNett&callback=3&deliv_ack=1"
Net::HTTP.start( ''api.clickatell.com'', 80 ) { |http|
result http.get(request).body }
end
-- G.
On 6/13/06, HH <lists@lastonepicked.com> wrote:> I am trying to query USPS to get shipping rates in my Rails app.
>
> I am currently fighting Net:HTTP and so I thought I''d ask for some
help.
>
> USPS only accepts GET requests, no POST... So, I have something along the
> following lines:
>
> @response_plain = Net::HTTP.get(USPS_SERVER_URL,
> "/ShippingAPITest.dll?API=RateV2&XML=#{data}")
>
> ''data'' is an XML string we generate elsewhere.
>
> All I am getting back is:
>
> getaddrinfo: No address associated with nodename
>
> Which I am guessing is the response from whatever low-level OS call
> implements this network call (?)...
>
> Well, if I print out the string that it''s using:
>
>
http://testing.shippingapis.com/ShippingAPITest.dll?API=RateV2&XML=<RateV2Re
> quest USERID="xxxxx"><Package
>
ID="0"><Service>PRIORITY</Service><ZipOrigination>10022</ZipOrigination><Zip
>
Destination>20008</ZipDestination><Pounds>10</Pounds><Ounces>5</Ounces><Cont
> ainer>Flat Rate
>
Box</Container><Size>REGULAR</Size></Package></RateV2Request>
>
> That URL works. It is the test server USPS URL and returns a response in a
> browser...
>
> So, what am I doing wrong? I have been trying variations of this for over
an
> hour and I''m ready to punch the wall.
>
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>