1

我应该向这个 web 服务发送一个 XML 请求,它返回一个 XML 响应,然后我可以在我这边使用那个 XML 响应。这是通过 endicia 提出的 USPS 运输标签请求。

POST /LabelService/EwsLabelService.asmx HTTP/1.1
Host: www.envmgr.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "www.envmgr.com/LabelService/GetPostageLabel"



<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:xsd="http:   //www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope /"><soap:Body>
<GetPostageLabel xmlns="www.envmgr.com/LabelService">
<LabelRequest Test="YES" LabelType="Default" LabelSize="4X6" ImageFormat="GIF"> 
<RequesterID>abcd</RequesterID> 
<AccountID>123456</AccountID> 
<PassPhrase>samplePassPhrase</PassPhrase> 
<MailClass>Priority</MailClass> 
<DateAdvance>0</DateAdvance> 
<WeightOz>15</WeightOz> 
<MailpieceShape>Parcel</MailpieceShape> 
<Stealth>FALSE</Stealth> 
<Services InsuredMail="OFF" DeliveryConfirmation=\u201dON\u201d SignatureConfirmation="ON" /> 
<Value>0</Value> 
<Description>Sample Label</Description> 
<PartnerCustomerID>12345ABCD</PartnerCustomerID> 
<PartnerTransactionID>6789EFGH</PartnerTransactionID> 
<ToName>Label Server Support</ToName> 
<ToCompany>Endicia</ToCompany> 
<ToAddress1>385 Sherman Ave.</ToAddress1> 
<ToCity>Palo Alto</ToCity> 
<ToState>CA</ToState> 
<ToPostalCode>94306</ToPostalCode> 
<ToZIP4>1864</ToZIP4> 
<ToDeliveryPoint>00</ToDeliveryPoint> 
<ToPhone>8005763279</ToPhone> 
<FromName>Benjamin Franklin</FromName> 
<ReturnAddress1>475 Enfant Plaza SW</ReturnAddress1> 
<FromCity>Washington</FromCity> 
<FromState>DC</FromState> 
<FromPostalCode>20260</FromPostalCode> 
<FromZIP4>0004</FromZIP4> 
<FromPhone>2025551212</FromPhone> 
<ResponseOptions PostagePrice="TRUE"/> 
</LabelRequest> 
</GetPostageLabel>
</soap:Body>
</soap:Envelope>

如何发送此请求并接收响应?

4

1 回答 1

2

如果您想自己构建soap内容可以使用URLConnection类发送http请求,或者您可以使用CXF框架,这将帮助您将webservice转换为java接口。

于 2013-11-13T08:15:15.070 回答