【问题标题】:Creating a HTTP Post Call for FedEx Web Services为 FedEx Web 服务创建 HTTP Post 调用
【发布时间】:2020-06-22 20:47:50
【问题描述】:

FedEx 网络服务文档状态:

FedEx 提供了一种纯 XML Web 服务解决方案,您可以使用它来发送交易,而无需使用为 Web 服务提供 SOAP 协议支持的工具。

以下是他们在文档中使用的示例:

Example 3: HTTP POST
The following HTTP POST example is a valid working example. It is not guaranteed to work for all
programming languages, applications, and host systems:
POST /xml HTTP/1.0
Referrer: YourCompanyNameGoesHere
Host: ws.fedex.com
Port: 443
Accept: image/gif, image/jpeg, image/pjpeg, text/plain, text/html, */*
Content-Type: text/xml
Content-length: %d
Your FedEx Transaction

------------------------

Each line is followed by one new line character except Content-length and the FedEx transaction. Two new
line characters follow the Content-length line. The FedEx transaction has no extra characters. The Content length line should have the length of the FedEx transaction in place of the %d variable.

如果我想在 kotlin 中使用 HTTP post 调用设置一个普通的 xml 事务,那需要什么?

这是我要发送的 SOAP WSDL。通过输入跟踪号跟踪货件

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v18="http://fedex.com/ws/track/v18">
   <soapenv:Header/>
   <soapenv:Body>
      <v18:TrackRequest>
         <v18:WebAuthenticationDetail>
            <v18:ParentCredential>
               <v18:Key>INPUT YOUR INFORMATION</v18:Key>
               <v18:Password>INPUT YOUR INFORMATION</v18:Password>
            </v18:ParentCredential>
            <v18:UserCredential>
               <v18:Key>INPUT YOUR INFORMATION</v18:Key>
               <v18:Password>INPUT YOUR INFORMATION</v18:Password>
            </v18:UserCredential>
         </v18:WebAuthenticationDetail>
         <v18:ClientDetail>
            <v18:AccountNumber>INPUT YOUR INFORMATION</v18:AccountNumber>
            <v18:MeterNumber>INPUT YOUR INFORMATION</v18:MeterNumber>
            <v18:Localization>
               <v18:LanguageCode>EN</v18:LanguageCode>
            </v18:Localization>
         </v18:ClientDetail>
         <v18:TransactionDetail>
            <v18:CustomerTransactionId>Track By Number_v18</v18:CustomerTransactionId>
            <v18:Localization>
               <v18:LanguageCode>EN</v18:LanguageCode>
               <v18:LocaleCode>US</v18:LocaleCode>
            </v18:Localization>
         </v18:TransactionDetail>
         <v18:Version>
            <v18:ServiceId>trck</v18:ServiceId>
            <v18:Major>18</v18:Major>
            <v18:Intermediate>0</v18:Intermediate>
            <v18:Minor>0</v18:Minor>
         </v18:Version>
         <v18:SelectionDetails>
            <v18:CarrierCode>FDXE</v18:CarrierCode>
            <v18:PackageIdentifier>
               <v18:Type>TRACKING_NUMBER_OR_DOORTAG</v18:Type>
               <v18:Value>INPUT YOUR INFORMATION</v18:Value>
            </v18:PackageIdentifier>
            <v18:ShipmentAccountNumber/>
            <v18:SecureSpodAccount/>
            <v18:Destination>
               <v18:GeographicCoordinates>rates evertitque aequora</v18:GeographicCoordinates>
            </v18:Destination>
         </v18:SelectionDetails>
      </v18:TrackRequest>
   </soapenv:Body>
</soapenv:Envelope>

【问题讨论】:

    标签: xml http kotlin soap fedex


    【解决方案1】:

    我最近成功地发送了一个请求并从 Fedex 获得了回复。在开发门户上进行初始设置(获取密钥等)后,构建和 XML 看起来像这样(示例流程发货请求)。

    关键的缺失部分是端点。您将无法使用 SOAP 端点。而是使用 https://wsbeta.fedex.com:443/xml

    此外,按照 Fedex 的建议更改以下标题

    接受 = image/gif, image/jpeg, image/pjpeg, text/plain, text/html, */*;

    内容类型 = 文本/xml

    祝你好运!

    <?xml version="1.0" encoding="UTF-8"?>
    <ProcessShipmentRequest xmlns="http://fedex.com/ws/ship/v26">
        <WebAuthenticationDetail>
            <UserCredential>
                <Key>Input your Key</Key>
                <Password>Input your pwd</Password>
            </UserCredential>
        </WebAuthenticationDetail>
        <ClientDetail>
            <AccountNumber>Input your Account Number</AccountNumber>
            <MeterNumber>Input your meter number</MeterNumber>
        </ClientDetail>
        <!-- <TransactionDetail>
            <CustomerTransactionId>Express Shipment Example</CustomerTransactionId>
        </TransactionDetail> -->
        <Version>
            <ServiceId>ship</ServiceId>
            <Major>26</Major>
            <Intermediate>0</Intermediate>
            <Minor>0</Minor>
        </Version>
        <RequestedShipment>
            <ShipTimestamp>2020-09-01T11:30:40.574Z</ShipTimestamp>
            <DropoffType>REGULAR_PICKUP</DropoffType>
            <ServiceType>FEDEX_GROUND</ServiceType>
            <PackagingType>YOUR_PACKAGING</PackagingType>
            <Shipper>
                <Contact>
                    <PersonName>John Doe</PersonName>
                    <CompanyName>FedEx</CompanyName>
                    <PhoneNumber>9015551234</PhoneNumber>
                </Contact>
                <Address>
                    <StreetLines>3610 Hacks Cross Road</StreetLines>
                    <StreetLines>First Floor</StreetLines>
                    <City>Memphis</City>
                    <StateOrProvinceCode>TN</StateOrProvinceCode>
                    <PostalCode>38125</PostalCode>
                    <CountryCode>US</CountryCode>
                </Address>
            </Shipper>
            <Recipient>
                <Contact>
                    <PersonName>Joe Customer</PersonName>
                    <CompanyName>ABC Widget Co</CompanyName>
                    <PhoneNumber>3305551234</PhoneNumber>
                </Contact>
                <Address>
                    <StreetLines>1234 Main Street</StreetLines>
                    <StreetLines>Suite 200</StreetLines>
                    <City>Akron</City>
                    <StateOrProvinceCode>OH</StateOrProvinceCode>
                    <PostalCode>44333</PostalCode>
                    <CountryCode>US</CountryCode>
                    <Residential>false</Residential>
                </Address>
            </Recipient>
            <ShippingChargesPayment>
                <PaymentType>SENDER</PaymentType>
                <Payor>
                    <ResponsibleParty>
                        <AccountNumber>Enter Account Number</AccountNumber>
                        <Contact />
                    </ResponsibleParty>
                </Payor>
            </ShippingChargesPayment>
            <LabelSpecification>
                <LabelFormatType>COMMON2D</LabelFormatType>
                <ImageType>PDF</ImageType>
                <LabelStockType>PAPER_4X6</LabelStockType>
            </LabelSpecification>
            <PackageCount>1</PackageCount>
            <RequestedPackageLineItems>
                <SequenceNumber>1</SequenceNumber>
                <Weight>
                    <Units>LB</Units>
                    <Value>10.0</Value>
                </Weight>
                <Dimensions>
                    <Length>5</Length>
                    <Width>5</Width>
                    <Height>5</Height>
                    <Units>IN</Units>
                </Dimensions>
                <CustomerReferences>
                    <CustomerReferenceType>CUSTOMER_REFERENCE</CustomerReferenceType>
                    <Value>ref1234</Value>
                </CustomerReferences>
            </RequestedPackageLineItems>
        </RequestedShipment>
    </ProcessShipmentRequest>
    

    【讨论】:

    • 天堂里有一个特别的地方适合你。你能告诉我你在哪里找到的吗?我只寻找费率服务。我得到了正确的费率,但看起来这实际上是在创建货件。
    • @KennethDale1,我一直在使用FedEx Web Services Developers Guide,以及FedEx Ship Service Schema。联邦快递也提供Rate Service
    • @DiegoColantoni - 我似乎无法找到如何为费率服务发送非 SOAP 给他们。在文档中,它说它应该是相同的,减去 SOAP env 和 body。但它不起作用。我还尝试将其发送到此处提供的 xml 端点,但不走运。如果你知道我不知道的事情,请告诉我。我真的很感激。我可能错过了一些微不足道的东西。截至目前,我自己序列化请求,在我发送它之前,我在 xml 前面加上 SOAP env 和 body 标签。它有效,但对我来说感觉很草率。
    • @KennethDale1,我已经设法使用纯 XML POST 请求获取费率,因此您的 xml 中可能有问题。注意事项:url 相同https://wsbeta.fedex.com:443/xml,根节点的xmlns 属性为fedex.com/ws/rate/v28ServiceId Version 节点的版本是 crsMajor 版本是 28。我还注意到,如果 xml 请求有空节点,或者节点的顺序错误,我会收到 500 个响应。如果你愿意,用你的 xml 请求开始一个新的帖子,我会看看。
    • @DiegoColantoni - 给你:stackoverflow.com/questions/65343524/…。先感谢您。一直忙于生产问题,否则我会早点回来。
    猜你喜欢
    • 2010-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多