[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

newbie... be gentle

Bea Martin

10/7/2007 3:57:00 PM

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=<TrackFi...
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?
--
Posted via http://www.ruby-....

2 Answers

mrpink

10/7/2007 4:37:00 PM

0

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"



--
kazaam <kazaam@oleco.net>

7stud 7stud

10/7/2007 4:51:00 PM

0

Bea Martin wrote:
> 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=<TrackFi...
> 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.



--
Posted via http://www.ruby-....