meteor - 使用 xml2js 无效字符解析 XML Soap 请求
问题描述
我正在尝试使用 API 端点设置我的 Meteor 应用程序,以便在我列出的项目发生更改或交易时接收 Ebay 卖家通知。
我按照 theMeteorChef 的指南编写了一个 api。
我在尝试使用流星 API 时遇到的第一个问题是,我body
在请求中出现了空对象,我读过自流星 1.12 以来所有 XML POST 请求都会发生这种情况。
遵循smilansky 的解决方案后,我能够将预期的 XML 放入 rawBody 并从context.request.rawBody
.
我现在遇到的问题是尝试解析 SOAP XML。这是我收到的错误:
[
Error: Invalid character in entity name
Line: 38
Column: 82
Char: =
]
我尝试了 ignoreAttrs、mergeAttrs 以及几个 xml2js 解析器选项的几种组合,以试图解决这个问题。
我正在使用 Postman 进行测试,这是我用于测试的原始文本/xml 输入:
(来自 eBay API 文档的示例 ItemListed 通知)
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://
www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header>
<ebl:RequesterCredentials soapenv:mustUnderstand="0" xmlns:ns="urn:ebay:apis:eBLBaseComponents"
xmlns:ebl="urn:ebay:apis:eBLBaseComponents">
<ebl:NotificationSignature xmlns:ebl="urn:ebay:apis:eBLBaseComponents">DYrq65GiZvg4cLFfW8J/Mg==</ebl:NotificationSignature>
</ebl:RequesterCredentials>
</soapenv:Header>
<soapenv:Body>
<GetItemResponse xmlns="urn:ebay:apis:eBLBaseComponents">
<Timestamp>2011-01-06T08:08:13.025Z</Timestamp>
<Ack>Success</Ack>
<CorrelationID>476457080</CorrelationID>
<Version>699</Version>
<Build>E699_CORE_BUNDLED_12457306_R1</Build>
<NotificationEventName>ItemListed</NotificationEventName>
<RecipientUserID>testuser_magicalbookseller</RecipientUserID>
<EIASToken>nY+sHZ2PrBmdj6wVnY+sEZ2PrA2dj6wFk4CpDZSLpwqdj6x9nY+seQ**</EIASToken>
<Item>
<AutoPay>false</AutoPay>
<BuyerProtection>ItemIneligible</BuyerProtection>
<BuyItNowPrice currencyID="USD">0.0</BuyItNowPrice>
<Country>US</Country>
<Currency>USD</Currency>
<GiftIcon>0</GiftIcon>
<HitCounter>NoHitCounter</HitCounter>
<ItemID>110066229557</ItemID>
<ListingDetails>
<Adult>false</Adult>
<BindingAuction>false</BindingAuction>
<CheckoutEnabled>true</CheckoutEnabled>
<ConvertedBuyItNowPrice currencyID="USD">0.0</ConvertedBuyItNowPrice>
<ConvertedStartPrice currencyID="USD">1.0</ConvertedStartPrice>
<ConvertedReservePrice currencyID="USD">0.0</ConvertedReservePrice>
<HasReservePrice>false</HasReservePrice>
<StartTime>2011-01-06T08:07:54.000Z</StartTime>
<EndTime>2011-01-13T08:07:54.000Z</EndTime>
<ViewItemURL>http://cgi.sandbox.ebay.com/ws/eBayISAPI.dll?ViewItem&item=110066229557&category=377</ViewItemURL>
<HasUnansweredQuestions>false</HasUnansweredQuestions>
<HasPublicMessages>false</HasPublicMessages>
<ExpressListing>false</ExpressListing>
</ListingDetails>
<ListingDuration>Days_7</ListingDuration>
<ListingType>Chinese</ListingType>
<Location>San Jose, California</Location>
<PaymentMethods>PayPal</PaymentMethods>
<PayPalEmailAddress>magicalbookseller@yahoo.com</PayPalEmailAddress>
<PrimaryCategory>
<CategoryID>377</CategoryID>
<CategoryName>Books:Fiction & Literature</CategoryName>
</PrimaryCategory>
<PrivateListing>false</PrivateListing>
<Quantity>1</Quantity>
<ReservePrice currencyID="USD">0.0</ReservePrice>
<ReviseStatus>
<ItemRevised>false</ItemRevised>
</ReviseStatus>
<Seller>
<AboutMePage>false</AboutMePage>
<Email>testuser_magicalbookseller@yahoo.com</Email>
<FeedbackScore>31</FeedbackScore>
<PositiveFeedbackPercent>100.0</PositiveFeedbackPercent>
<FeedbackPrivate>false</FeedbackPrivate>
<FeedbackRatingStar>Yellow</FeedbackRatingStar>
<IDVerified>true</IDVerified>
<eBayGoodStanding>true</eBayGoodStanding>
<NewUser>false</NewUser>
<RegistrationDate>2010-01-01T00:00:00.000Z</RegistrationDate>
<Site>US</Site>
<Status>Confirmed</Status>
<UserID>testuser_magicalbookseller</UserID>
<UserIDChanged>false</UserIDChanged>
<UserIDLastChanged>2007-11-29T18:43:54.000Z</UserIDLastChanged>
<VATStatus>NoVATTax</VATStatus>
<SellerInfo>
<AllowPaymentEdit>true</AllowPaymentEdit>
<CheckoutEnabled>true</CheckoutEnabled>
<CIPBankAccountStored>false</CIPBankAccountStored>
<GoodStanding>true</GoodStanding>
<LiveAuctionAuthorized>false</LiveAuctionAuthorized>
<MerchandizingPref>OptIn</MerchandizingPref>
<QualifiesForB2BVAT>false</QualifiesForB2BVAT>
<StoreOwner>true</StoreOwner>
<StoreURL>http://www.stores.sandbox.ebay.com/id=132854966</StoreURL>
<ExpressEligible>false</ExpressEligible>
<ExpressWallet>false</ExpressWallet>
<SafePaymentExempt>false</SafePaymentExempt>
</SellerInfo>
<MotorsDealer>false</MotorsDealer>
</Seller>
<SellingStatus>
<BidCount>0</BidCount>
<BidIncrement currencyID="USD">0.25</BidIncrement>
<ConvertedCurrentPrice currencyID="USD">1.0</ConvertedCurrentPrice>
<CurrentPrice currencyID="USD">1.0</CurrentPrice>
<LeadCount>0</LeadCount>
<MinimumToBid currencyID="USD">1.0</MinimumToBid>
<QuantitySold>0</QuantitySold>
<ReserveMet>true</ReserveMet>
<SecondChanceEligible>false</SecondChanceEligible>
<ListingStatus>Active</ListingStatus>
</SellingStatus>
<ShippingDetails>
<ApplyShippingDiscount>false</ApplyShippingDiscount>
<CalculatedShippingRate>
<OriginatingPostalCode>95125</OriginatingPostalCode>
<PackageDepth measurementSystem="English" unit="inches">2</PackageDepth>
<PackageLength measurementSystem="English" unit="inches">10</PackageLength>
<PackageWidth measurementSystem="English" unit="inches">7</PackageWidth>
<PackagingHandlingCosts currencyID="USD">0.0</PackagingHandlingCosts>
<ShippingIrregular>false</ShippingIrregular>
<ShippingPackage>PackageThickEnvelope</ShippingPackage>
<WeightMajor measurementSystem="English" unit="lbs">2</WeightMajor>
<WeightMinor measurementSystem="English" unit="oz">0</WeightMinor>
</CalculatedShippingRate>
<SalesTax>
<SalesTaxPercent>0.0</SalesTaxPercent>
<ShippingIncludedInTax>false</ShippingIncludedInTax>
</SalesTax>
<ShippingServiceOptions>
<ShippingService>USPSMedia</ShippingService>
<ShippingServicePriority>1</ShippingServicePriority>
<ExpeditedService>false</ExpeditedService>
<ShippingTimeMin>2</ShippingTimeMin>
<ShippingTimeMax>9</ShippingTimeMax>
</ShippingServiceOptions>
<ShippingType>Calculated</ShippingType>
<ThirdPartyCheckout>false</ThirdPartyCheckout>
<ExcludeShipToLocation>Asia</ExcludeShipToLocation>
<ExcludeShipToLocation>Middle East</ExcludeShipToLocation>
<ExcludeShipToLocation>Southeast Asia</ExcludeShipToLocation>
<SellerExcludeShipToLocationsPreference>true</SellerExcludeShipToLocationsPreference>
</ShippingDetails>
<ShipToLocations>US</ShipToLocations>
<Site>US</Site>
<StartPrice currencyID="USD">1.0</StartPrice>
<Storefront>
<StoreCategoryID>1</StoreCategoryID>
<StoreCategory2ID>0</StoreCategory2ID>
<StoreURL>http://www.stores.sandbox.ebay.com/id=132854966</StoreURL>
</Storefront>
<TimeLeft>P6DT23H59M42S</TimeLeft>
<Title>Harry Potter and the Philosopher's Stone</Title>
<UUID>CD751A9973E249ABB880E1B2DF65B50B</UUID>
<HitCount>0</HitCount>
<LocationDefaulted>true</LocationDefaulted>
<GetItFast>false</GetItFast>
<PostalCode>95125</PostalCode>
<PictureDetails>
<GalleryType>Gallery</GalleryType>
<GalleryURL>http://i1.sandbox.ebayimg.com/03/i/00/3e/60/d7_1.JPG?set_id=8800005007</GalleryURL>
<PhotoDisplay>PicturePack</PhotoDisplay>
<PictureURL>http://i1.sandbox.ebayimg.com/03/i/00/3e/60/d7_1.JPG?set_id=8800005007</PictureURL>
</PictureDetails>
<DispatchTimeMax>3</DispatchTimeMax>
<ProxyItem>false</ProxyItem>
<BuyerGuaranteePrice currencyID="USD">20000.0</BuyerGuaranteePrice>
<IntangibleItem>false</IntangibleItem>
<ReturnPolicy>
<RefundOption>MoneyBack</RefundOption>
<Refund>Money Back</Refund>
<ReturnsWithinOption>Days_30</ReturnsWithinOption>
<ReturnsWithin>30 Days</ReturnsWithin>
<ReturnsAcceptedOption>ReturnsAccepted</ReturnsAcceptedOption>
<ReturnsAccepted>Returns Accepted</ReturnsAccepted>
<Description>This is the first book in the Harry Potter series. In excellent condition!</Description>
<ShippingCostPaidByOption>Buyer</ShippingCostPaidByOption>
<ShippingCostPaidBy>Buyer</ShippingCostPaidBy>
</ReturnPolicy>
<PaymentAllowedSite>eBayMotors</PaymentAllowedSite>
<PaymentAllowedSite>CanadaFrench</PaymentAllowedSite>
<PaymentAllowedSite>Canada</PaymentAllowedSite>
<PaymentAllowedSite>US</PaymentAllowedSite>
<ConditionID>1000</ConditionID>
<ConditionDisplayName>Brand New</ConditionDisplayName>
</Item>
</GetItemResponse>
</soapenv:Body>
</soapenv:Envelope>
此外,在类似生产的环境中对其进行测试时,我收到关于request entity too large
. 我现在不知道该怎么做。
任何援助将不胜感激。
提前感谢您的宝贵时间。
解决方案
The problem was the url within the <ViewItemURL>
has an ampersand in it, which is an invalid character in XML, &
must be &
.
Luckily, this was an example of a bad example in eBay docs. This error is not happening on live, because the ViewItemURL is being properly escaped in the actual eBay notifications.
When I escaped the ampersands in the eBay example myself, it worked just fine.
推荐阅读
- r - R for-loop for ftp地址中的变量
- html - 由于文本内容,div 中的按钮呈现方式不同
- terraform - Terraform iam_policy_document - 差异。资源与本金
- angular - 如何使用 ngx-pagination 对 div 进行分页
- webrtc - NACK 在 webrtc 中是如何工作的?
- c# - 从 c# 到 c 应用程序的串行端口通信问题
- android - AppWidget Imageview updatePeriodMillis
- c# - 无法从自定义域中解开 COM 实例
- javascript - 如何将点的对象从js传递到java作为列表?
- python - pyOpenGL 三角形没有被绘制