2015-08-21 32 views
5

npm isteği ile bir SOAP API için bir yazı Şekillendirme: Bunu yaparakBunu başarmak için çalışıyorum

POST /oms/order.asmx HTTP/1.1 
Host:myserver.com 
Content-Type: text/xml; 
charset=utf-8 
Content-Length: length 
SOAPAction: "http://shipping_software/AddOrder" 

:

var newOrder = buildOrder(orderInfo); 
var soapOptions = { 
    uri: '/oms/order.asmx', 
    headers: { 
     'Content-Type': 'text/xml', 
     'charset': 'utf-8', 
     'Content-Length': newOrder.length.toString(), 
     'SOAPAction': 'http://shipping_software/AddOrder', 
     'Host': 'myserver.com', 
     'Connection': 'keep-alive' 
    }, 
    method: 'POST', 
    body: newOrder //New order is properly formed xml as a String 
} 
request(soapOptions, function(err, response) { 
     console.log(err); 
     console.log(response); 
    }) 
    // console.log(newOrder); 
}); 

Bu, şu anda 'geçersiz uri' ile geri gelir, ne zaman URI'yi http://myserver.com/oms/order.asmx olarak değiştiriyorum hala 400 yanıt kodu alıyorum.

Düzenleme: İçerik türünü tek satırda Content-Type: text/html; charset=utf-8 herhangi bir iyileştirme olmaksızın düzelttim.

Edit2: XML verilerini oluşturmak için XMLBuilder kullanıyorum ve bunu bir dizeye dönüştürmeden göndermeyi denedim, ancak SOAP API'sinin bağlantısı zaman aşımına uğradı.

Edit3: tam sabun isteği:

POST /oms/order.asmx HTTP/1.1 
Host: myserver.com 
Content-Type: text/xml; charset=utf-8 
Content-Length: length 
SOAPAction: "http://oms/AddOrder" 

<?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:Header> 
    <AuthenticationHeader xmlns="http://sma-promail/"> 
     <Username>string</Username> 
     <Password>string</Password> 
    </AuthenticationHeader> 
    <DebugHeader xmlns="http://sma-promail/"> 
     <Debug>boolean</Debug> 
     <Request>string</Request> 
    </DebugHeader> 
    </soap:Header> 
    <soap:Body> 
    <AddOrder xmlns="http://sma-promail/"> 
     <order> 
     <Header> 
      <ID>string</ID> 
      <EntryDate>dateTime</EntryDate> 
      <OrderEntryView> 
      <SeqID>int</SeqID> 
      <Description>string</Description> 
      </OrderEntryView> 
      <ReferenceNumber>string</ReferenceNumber> 
      <PONumber>string</PONumber> 
      <Comments>string</Comments> 
      <IpAddress>string</IpAddress> 
      <ApprovalComment>string</ApprovalComment> 
      <InsertDate>dateTime</InsertDate> 
     </Header> 
     <Classification> 
      <CampaignID>string</CampaignID> 
      <ResponseMedia> 
      <Description>string</Description> 
      </ResponseMedia> 
      <Source> 
      <Description>string</Description> 
      </Source> 
      <Issue> 
      <Issue>string</Issue> 
      </Issue> 
      <CustomerProject> 
      <ID>string</ID> 
      </CustomerProject> 
      <CustomerCode>string</CustomerCode> 
      <Store>string</Store> 
      <Department>string</Department> 
      <DistributionCenter>string</DistributionCenter> 
      <Vendor>string</Vendor> 
     </Classification> 
     <Shipping> 
      <FreightCarrier> 
      <Name>string</Name> 
      </FreightCarrier> 
      <FreightService> 
      <Description>string</Description> 
      </FreightService> 
      <FreightAccount> 
      <SeqID>int</SeqID> 
      <Description>string</Description> 
      <FreightCarrier xsi:nil="true" /> 
      <Person xsi:nil="true" /> 
      <ThirdAcctNo>string</ThirdAcctNo> 
      <NonResident>boolean</NonResident> 
      </FreightAccount> 
      <ShippingOption> 
      <Description>string</Description> 
      </ShippingOption> 
      <FreightCode>string</FreightCode> 
      <FreightCodeDescription>string</FreightCodeDescription> 
      <ShipComments>string</ShipComments> 
      <NeededBy>string</NeededBy> 
      <Rush>boolean</Rush> 
      <ReleaseDate>dateTime</ReleaseDate> 
      <ThirdPartyType>int</ThirdPartyType> 
      <ThirdAccountNumber>string</ThirdAccountNumber> 
      <NCShip>boolean</NCShip> 
      <NCPack>boolean</NCPack> 
      <NCOffers>boolean</NCOffers> 
      <NCHandling>boolean</NCHandling> 
      <NCOffShipHandling>boolean</NCOffShipHandling> 
      <NCSpecialHandling>boolean</NCSpecialHandling> 
      <NCRush>boolean</NCRush> 
     </Shipping> 
     <Money> 
      <PriceClass> 
      <SeqID>int</SeqID> 
      <Description>string</Description> 
      </PriceClass> 
      <ShippingHandlingCharge>decimal</ShippingHandlingCharge> 
      <RushHandlingCharge>decimal</RushHandlingCharge> 
      <NoChargeType> 
      <Description>string</Description> 
      </NoChargeType> 
      <DiscountAmount>decimal</DiscountAmount> 
      <DiscountPercent>float</DiscountPercent> 
      <DiscountCode> 
      <ID>string</ID> 
      <Description>string</Description> 
      </DiscountCode> 
      <Coupon> 
      <Code>string</Code> 
      </Coupon> 
      <SpecialHandlingCharge>decimal</SpecialHandlingCharge> 
      <CreditAmount>decimal</CreditAmount> 
      <GiftCertificate> 
      <UID>string</UID> 
      <Amount>decimal</Amount> 
      </GiftCertificate> 
      <GiftCertificateAmount>decimal</GiftCertificateAmount> 
      <TaxPercent>decimal</TaxPercent> 
      <NoChargeAmount>decimal</NoChargeAmount> 
      <TaxAmount>decimal</TaxAmount> 
     </Money> 
     <Payment> 
      <PaymentType> 
      <Description>string</Description> 
      <Sequence>int</Sequence> 
      </PaymentType> 
      <PaymentAmount>decimal</PaymentAmount> 
      <CCNumber>string</CCNumber> 
      <CCExpirationDate>string</CCExpirationDate> 
      <CSC>string</CSC> 
      <ARReference>string</ARReference> 
     </Payment> 
     <OrderVariables> 
      <OrderVariable> 
      <SeqID>int</SeqID> 
      <VariableField xsi:nil="true" /> 
      <Value>string</Value> 
      </OrderVariable> 
      <OrderVariable> 
      <SeqID>int</SeqID> 
      <VariableField xsi:nil="true" /> 
      <Value>string</Value> 
      </OrderVariable> 
     </OrderVariables> 
     <OrderedBy> 
      <ORDOBY> 
      <SeqID>int</SeqID> 
      <CustomerID>string</CustomerID> 
      </ORDOBY> 
      <FullName>string</FullName> 
      <FullNameWithSuffix>string</FullNameWithSuffix> 
      <CityStateZip>string</CityStateZip> 
      <CityStateZipCountry>string</CityStateZipCountry> 
      <CompoundAddress>string</CompoundAddress> 
     </OrderedBy> 
     <ShipTo> 
      <OrderShipTo> 
      <SeqID>int</SeqID> 
      <Flag>Other or OrderedBy</Flag> 
      <Key>string</Key> 
      <NeededBy>string</NeededBy> 
      <ReleaseDate>dateTime</ReleaseDate> 
      <Rush>boolean</Rush> 
      <RushHandling>decimal</RushHandling> 
      <Comments>string</Comments> 
      <FreightCarrier xsi:nil="true" /> 
      <FreightService xsi:nil="true" /> 
      <ThirdPartyType>int</ThirdPartyType> 
      <ThirdPartyAccountNumber>string</ThirdPartyAccountNumber> 
      <FreightCode>string</FreightCode> 
      <FreightCodeDescription>string</FreightCodeDescription> 
      <SpecialHandling xsi:nil="true" /> 
      <SpecialHandlingCharge>decimal</SpecialHandlingCharge> 
      <ShippingHandlingCharge>decimal</ShippingHandlingCharge> 
      <FullName>string</FullName> 
      <FullNameWithSuffix>string</FullNameWithSuffix> 
      <CityStateZip>string</CityStateZip> 
      <CityStateZipCountry>string</CityStateZipCountry> 
      <CompoundAddress>string</CompoundAddress> 
      <PickPacks xsi:nil="true" /> 
      </OrderShipTo> 
      <OrderShipTo> 
      <SeqID>int</SeqID> 
      <Flag>Other or OrderedBy</Flag> 
      <Key>string</Key> 
      <NeededBy>string</NeededBy> 
      <ReleaseDate>dateTime</ReleaseDate> 
      <Rush>boolean</Rush> 
      <RushHandling>decimal</RushHandling> 
      <Comments>string</Comments> 
      <FreightCarrier xsi:nil="true" /> 
      <FreightService xsi:nil="true" /> 
      <ThirdPartyType>int</ThirdPartyType> 
      <ThirdPartyAccountNumber>string</ThirdPartyAccountNumber> 
      <FreightCode>string</FreightCode> 
      <FreightCodeDescription>string</FreightCodeDescription> 
      <SpecialHandling xsi:nil="true" /> 
      <SpecialHandlingCharge>decimal</SpecialHandlingCharge> 
      <ShippingHandlingCharge>decimal</ShippingHandlingCharge> 
      <FullName>string</FullName> 
      <FullNameWithSuffix>string</FullNameWithSuffix> 
      <CityStateZip>string</CityStateZip> 
      <CityStateZipCountry>string</CityStateZipCountry> 
      <CompoundAddress>string</CompoundAddress> 
      <PickPacks xsi:nil="true" /> 
      </OrderShipTo> 
     </ShipTo> 
     <BillTo> 
      <Flag>Other or OrderedBy or DoNotUse or ShipTo</Flag> 
      <FullName>string</FullName> 
      <FullNameWithSuffix>string</FullNameWithSuffix> 
      <CityStateZip>string</CityStateZip> 
      <CityStateZipCountry>string</CityStateZipCountry> 
      <CompoundAddress>string</CompoundAddress> 
     </BillTo> 
     <Offers> 
      <OfferOrdered> 
      <Offer xsi:nil="true" /> 
      <Quantity>int</Quantity> 
      <CanceledQuantity>int</CanceledQuantity> 
      <OrderShipTo xsi:nil="true" /> 
      <OrderShipToKey xsi:nil="true" /> 
      <PriceType>unsignedByte</PriceType> 
      <UnitPrice>decimal</UnitPrice> 
      <ShipType>short</ShipType> 
      <ShippingHandling>decimal</ShippingHandling> 
      <Discounts>decimal</Discounts> 
      <DiscountPercent>int</DiscountPercent> 
      <DocumentID>string</DocumentID> 
      <SeqID>int</SeqID> 
      <CloneLine>int</CloneLine> 
      <Unapproved>boolean</Unapproved> 
      <ShipToKey>string</ShipToKey> 
      <FgnOrder>string</FgnOrder> 
      <Comments>string</Comments> 
      <RCOrderKey>string</RCOrderKey> 
      <Recurring>boolean</Recurring> 
      <LineNumber>int</LineNumber> 
      <Variables xsi:nil="true" /> 
      <ProductDetails xsi:nil="true" /> 
      </OfferOrdered> 
      <OfferOrdered> 
      <Offer xsi:nil="true" /> 
      <Quantity>int</Quantity> 
      <CanceledQuantity>int</CanceledQuantity> 
      <OrderShipTo xsi:nil="true" /> 
      <OrderShipToKey xsi:nil="true" /> 
      <PriceType>unsignedByte</PriceType> 
      <UnitPrice>decimal</UnitPrice> 
      <ShipType>short</ShipType> 
      <ShippingHandling>decimal</ShippingHandling> 
      <Discounts>decimal</Discounts> 
      <DiscountPercent>int</DiscountPercent> 
      <DocumentID>string</DocumentID> 
      <SeqID>int</SeqID> 
      <CloneLine>int</CloneLine> 
      <Unapproved>boolean</Unapproved> 
      <ShipToKey>string</ShipToKey> 
      <FgnOrder>string</FgnOrder> 
      <Comments>string</Comments> 
      <RCOrderKey>string</RCOrderKey> 
      <Recurring>boolean</Recurring> 
      <LineNumber>int</LineNumber> 
      <Variables xsi:nil="true" /> 
      <ProductDetails xsi:nil="true" /> 
      </OfferOrdered> 
     </Offers> 
     <OrderRecurrenceSchedule> 
      <RecurrenceSchedules> 
      <SeqID>int</SeqID> 
      <ID>string</ID> 
      <Description>string</Description> 
      <Definition>string</Definition> 
      <DefinitionDetail>string</DefinitionDetail> 
      <Schedule>EveryXDays or EveryXWeeks or EveryXMonths</Schedule> 
      <ScheduleCount>int</ScheduleCount> 
      <Cycle>Rolling or Custom</Cycle> 
      <StartCycleDate>dateTime</StartCycleDate> 
      <DaysToJoin>int</DaysToJoin> 
      <MonthlyRecurrenceType>DayOfMonth or WeekOfMonthAndDayOfWeek</MonthlyRecurrenceType> 
      <MinimumRecurrences>int</MinimumRecurrences> 
      <MaximumRecurrences>int</MaximumRecurrences> 
      <RecurrenceIncrement>int</RecurrenceIncrement> 
      <AllowInfiniteRecurrence>boolean</AllowInfiniteRecurrence> 
      <InfiniteTag>string</InfiniteTag> 
      <DurationTag>string</DurationTag> 
      <ExpirationDate>dateTime</ExpirationDate> 
      <NextCycleDate>dateTime</NextCycleDate> 
      <HasValidCycleDate>boolean</HasValidCycleDate> 
      <AnyOffer>boolean</AnyOffer> 
      <RecurrenceScheduleShippingOptions xsi:nil="true" /> 
      </RecurrenceSchedules> 
      <RecurrenceOfferFlag>boolean</RecurrenceOfferFlag> 
      <RecurrenceShippingOption> 
      <Description>string</Description> 
      </RecurrenceShippingOption> 
      <RecurrenceSpecialHandlingCharge>decimal</RecurrenceSpecialHandlingCharge> 
      <NumberRecurrence>int</NumberRecurrence> 
     </OrderRecurrenceSchedule> 
     <OrderBudget> 
      <Person> 
      <Name xsi:nil="true" /> 
      <CompanyInfo xsi:nil="true" /> 
      <Address xsi:nil="true" /> 
      <ContactInfo xsi:nil="true" /> 
      <BillingInfo xsi:nil="true" /> 
      <Variables xsi:nil="true" /> 
      </Person> 
     </OrderBudget> 
     </order> 
    </AddOrder> 
    </soap:Body> 
</soap:Envelope> 
HTTP/1.1 200 OK 
Content-Type: text/xml; charset=utf-8 
Content-Length: length 

<?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:Header> 
    <DebugHeader xmlns="http://sma-promail/"> 
     <Debug>boolean</Debug> 
     <Request>string</Request> 
    </DebugHeader> 
    </soap:Header> 
    <soap:Body> 
    <AddOrderResponse xmlns="http://sma-promail/"> 
     <AddOrderResult> 
     <OrderSeqID>int</OrderSeqID> 
     <OrderID>string</OrderID> 
     </AddOrderResult> 
    </AddOrderResponse> 
    </soap:Body> 
</soap:Envelope> 
+0

Sabit yanlış nereye gittiğini anlamaya - HTTP istek alıntı sen orada değilmi ekledik t tamamlayın (veya en azından, bunları Node.js kodunuza başlık olarak eklediniz, ancak hepsi başlıklara benzemiyor). [Tag: curl] ile başarılı bir istekte bulunabilir misiniz? Eğer öyleyse, sorunuzda bu tam kıvırma komutunu gönderin. – brandonscript

+0

Başlıklar düzgün ayarlanmış gibi görünüyor: _header: 'POST /oms/order.asmx HTTP/1.1 \ r \ nContent-Type: text/xml \ r \ ncharset: utf-8 \ r \ nContent-Length: 1161 \ r \ nSOAPAction: http: // oms/AddOrder \ r \ nHost: myserver.com \ r \ nConnection: canlı tutma \ r \ n \ r \ n ' – goofiw

+0

Tam bir HTTP isteği görmeden dürüstçe Sunucunuzun neden 400'ü geri çektiğini anlamak imkansız. – brandonscript

cevap

2

bugüne kadar Spekülasyon, ancak tüm başlıkları uygun şekilde ayarlandığında varsayarak, göze çarpan bir şey content-type başlıktır - sen var sende ve charset çoklu anahtarlara ayrılmıştır: değer çiftleri; tek satırda olmalıdır: Eğer sorunuzu belirtildiği gibi

var newOrder = buildOrder(orderInfo); 
var soapOptions = { 
    uri: 'http://myserver.com/oms/order.asmx', 
    headers: { 
     'Content-Type': 'text/xml; charset=utf-8', 
     'Content-Length': newOrder.length.toString(), 
     'SOAPAction': 'http://shipping_software/AddOrder', 
     'Host': 'myserver.com', 
     'Connection': 'keep-alive' 
    }, 
    method: 'POST', 
    body: newOrder //New order is properly formed xml as a String 
} 
request(soapOptions, function(err, response) { 
     console.log(err); 
     console.log(response); 
    }) 
    // console.log(newOrder); 
}); 

Ayrıca, uri tam nitelikli bir URL değil, sadece yol eki olduğundan emin olun.

+0

Tamam - kıvrımla çalışmaya çalışın. Eğer yapabiliyorsanız, lütfen bu komutu sorunuza ekleyin. – brandonscript

+0

Çalışmak için kıvrık bir sabun çağrısı almaya çalışıyorum, ancak hiçbir şey iade edilmiyor: curl -H 'Content-Type: text/xml; charset = utf-8 '-H' İçerik-Uzunluğu: 1150 '-H' SOAPAction: http: // sma-promail/AddOrder '--data @ sampleOrder.txt http://myserver.com/pmomsws/order.asmx wsdl – goofiw

+0

Hrm, peki bu işe yaramazsan, sorun kesinlikle budur. Sunucunuzda bazı dokümanlar bulmanızı veya bir çalışma isteği örneği bulmanızı öneririz. – brandonscript

2

Biraz sonrası başlığından konu dışı gider, ama sadece düğüm http ile gidiş sona erdi:

var newOrder = "<?xml version='1.0' encoding='utf-8'?><soap:Envelope><soap:Header>.....</soap:Envelope>" 

    var postOptions = { 
     hostname: 'server.com', 
     port: 80, 
     path: '/oms/order.asmx?wsdl', 
     method: 'POST', 
     headers: { 
     'Host':'server.com', 
     'Content-Type':'text/xml;charset=utf-8', 
     'Content-Length':newOrder.length, 
     'SOAPAction':"http://sma-promail/AddOrder", 
     } 
    }; 

    var req = http.request(postOptions, function(res) { 
     console.log('STATUS: ' + res.statusCode); 
     console.log('HEADERS: ' + JSON.stringify(res.headers)); 
     res.setEncoding('utf8'); 
     res.on('data', function (chunk) { 
     console.log('BODY: ' + chunk); 
     }); 
    }); 

    req.on('error', function(e) { 
     console.log('problem with request: ' + e.message); 
    }); 

    // write data to request body 
    req.write(newOrder); 
    req.end(); 
    }); 
İlgili konular