0

I'm trying to mimic the POST request that happens at Fedex.com when they're loading tracking information for a package.

The URL that the request posts to is https://www.fedex.com/trackingCal/track

and the data that it sends in the request to get the full JSON is

#{"TrackPackagesRequest":{"appType":"wtrk","uniqueKey":"","processingParameters":{"anonymousTransaction":true,"clientId":"WTRK","returnDetailedErrors":true,"returnLocalizedDateTime":false},"trackingInfoList":[{"trackNumberInfo":{"trackingNumber":"61297641750622453544","trackingQualifier":"","trackingCarrier":""}}]}}

My goal is in my Rails app to feed a tracking number into this post request and mimic what the site is doing, hitting the endpoint and getting back the JSON or XML response to parse and use in my app.

I'm unclear as to how to do this and the efforts I've made thus far with net/http and open-uri haven't worked.

Any help here would be much appreciated

4

1 回答 1

-1

希望这会帮助你。[未测试]

require "net/http"
url = URI.parse("https://www.fedex.com/trackingCal/track")
args = {
    "TrackPackagesRequest"= {
        "appType"= "wtrk",
        "uniqueKey"= "",
        "processingParameters"= {
            "anonymousTransaction"= true,
            "clientId"= "WTRK",
            "returnDetailedErrors"= true,
            "returnLocalizedDateTime"= false
        },
        "trackingInfoList"= [
            {
                "trackNumberInfo"= {
                    "trackingNumber"= "61297641750622453544",
                    "trackingQualifier"= "",
                    "trackingCarrier"= ""
                }
            }
        ]
    }
resp, data = Net::HTTP.post_form(url, args)
response = JSON.parse(data)
print response.inspect
于 2013-11-01T05:41:40.527 回答