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?
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?