newbie... be gentle

B

Bea Martin

I am trying to access the US Postal Service web tool for tracking. I am
new to Ruby and web programming in general so if this is a really stupid
question I apologize in advance.

According to their site the if I access the test server with:
http://testing.shippingapis.com/ShippingAPITest.dll?API=TrackV2&XML=<TrackFieldRequest
USERID="xxxxxxxxxxxx"><TrackID
ID="xxxxxxxxxxxxx"></TrackID></TrackFieldRequest>

I should get a test response. Sure enough, if I substitute in the
correct values for userid, trackid and paste it into my browser I get
the correct "test" response. Now to do it in Ruby...

I wrote:

begin
request_body = <<-EOT
<TrackFieldRequest USERID="#{@user_id}">
<TrackID ID="#{@track_id}"></TrackID>
</TrackFieldRequest>
EOT
end

@path = '/ShippingAPITest.dll?API=TrackV2?XML='
http_address = 'testing.shippingapis.com'
@headers = {'Content-Type' => 'text/xml'}
@http = Net::HTTP.new(http_address)

headers = @headers
headers['Content-Length'] = request_body.length.to_s

response = nil
@http.start do |http|
response = http.request_post(@path, request_body)
end

puts "Response is: #{response.code} => #{response.header}
#{response.body}"

and the response I get is:
Response is: 501 => #<Net::HTTPNotImplemented:0x2e62754>
<HEAD><TITLE>HTTP Error 501</TITLE></HEAD><BODY><H1>NOT
IMPLEMENTED</H1>The server is unable to perform the method
<b>API=TrackV2?XML=</b> at this time.</BODY>

</body></html>


I am sure this is something really basic, can anyone help me out?
 
K

kazaam

Well I don't know this webservice so I can't test it totally but why do you make it such complicated? You don't have to assemble the http-header yourself... little example:


#!/usr/bin/env ruby
$Verbose=true

require 'net/http'

user_id = '32423423'
track_id = '5454545'

Net::HTTP.get_print 'testing.shippingapis.com', "/ShippingAPITest.dll?API=TrackV2&XML=%3CTrackFieldRequest%20USERID=%22#{user_id}%22%3E%3CTrackID%20ID=%22#{track_id}%22%3E%3C/TrackID%3E%3C/TrackFieldRequest%3E"
 
7

7stud --

Bea said:
I am trying to access the US Postal Service web tool for tracking. I am
new to Ruby and web programming in general so if this is a really stupid
question I apologize in advance.

According to their site the if I access the test server with:
http://testing.shippingapis.com/ShippingAPITest.dll?API=TrackV2&XML=<TrackFieldRequest
USERID="xxxxxxxxxxxx"><TrackID
ID="xxxxxxxxxxxxx"></TrackID></TrackFieldRequest>

For one thing, that's a 'get' request, which means all the data you are
transmitting is tacked onto the end of the url. While this:
response = http.request_post(@path, request_body)
end

is a 'post' request, which means the data is not tacked onto the end of
the url, and it is sent by other means. However, if a program on the
server is expecting the data to be attached to the end of the url,
that's where it is going to look for it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top