title: Forming a post to a SOAP api with npm request
body: <p>I'm trying to accomplish this:</p>
  
  <pre><code>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"
  </code></pre>
  
  <p>By doing this:</p>
  
  <pre><code>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);
  });
  </code></pre>
  
  <p>This currently comes back with 'invalid uri', when I change the URI to <code>http://myserver.com/oms/order.asmx</code> I still get a 400 response code.</p>
  
  <p><strong>Edit:</strong> I fixed the content type to be on one line <code>Content-Type: text/html; charset=utf-8</code> without any improvement.</p>
  
  <p><strong>Edit2:</strong>  I'm using XMLBuilder to build my XML data and tried submitting it without converting it to a string, however the connection from the SOAP API times out.</p>
  
  <p><strong>Edit3:</strong> full soap request:</p>
  
  <pre><code>POST /oms/order.asmx HTTP/1.1
  Host: myserver.com
  Content-Type: text/xml; charset=utf-8
  Content-Length: length
  SOAPAction: "http://oms/AddOrder"
  
  &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;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/"&gt;
    &lt;soap:Header&gt;
      &lt;AuthenticationHeader xmlns="http://sma-promail/"&gt;
        &lt;Username&gt;string&lt;/Username&gt;
        &lt;Password&gt;string&lt;/Password&gt;
      &lt;/AuthenticationHeader&gt;
      &lt;DebugHeader xmlns="http://sma-promail/"&gt;
        &lt;Debug&gt;boolean&lt;/Debug&gt;
        &lt;Request&gt;string&lt;/Request&gt;
      &lt;/DebugHeader&gt;
    &lt;/soap:Header&gt;
    &lt;soap:Body&gt;
      &lt;AddOrder xmlns="http://sma-promail/"&gt;
        &lt;order&gt;
          &lt;Header&gt;
            &lt;ID&gt;string&lt;/ID&gt;
            &lt;EntryDate&gt;dateTime&lt;/EntryDate&gt;
            &lt;OrderEntryView&gt;
              &lt;SeqID&gt;int&lt;/SeqID&gt;
              &lt;Description&gt;string&lt;/Description&gt;
            &lt;/OrderEntryView&gt;
            &lt;ReferenceNumber&gt;string&lt;/ReferenceNumber&gt;
            &lt;PONumber&gt;string&lt;/PONumber&gt;
            &lt;Comments&gt;string&lt;/Comments&gt;
            &lt;IpAddress&gt;string&lt;/IpAddress&gt;
            &lt;ApprovalComment&gt;string&lt;/ApprovalComment&gt;
            &lt;InsertDate&gt;dateTime&lt;/InsertDate&gt;
          &lt;/Header&gt;
          &lt;Classification&gt;
            &lt;CampaignID&gt;string&lt;/CampaignID&gt;
            &lt;ResponseMedia&gt;
              &lt;Description&gt;string&lt;/Description&gt;
            &lt;/ResponseMedia&gt;
            &lt;Source&gt;
              &lt;Description&gt;string&lt;/Description&gt;
            &lt;/Source&gt;
            &lt;Issue&gt;
              &lt;Issue&gt;string&lt;/Issue&gt;
            &lt;/Issue&gt;
            &lt;CustomerProject&gt;
              &lt;ID&gt;string&lt;/ID&gt;
            &lt;/CustomerProject&gt;
            &lt;CustomerCode&gt;string&lt;/CustomerCode&gt;
            &lt;Store&gt;string&lt;/Store&gt;
            &lt;Department&gt;string&lt;/Department&gt;
            &lt;DistributionCenter&gt;string&lt;/DistributionCenter&gt;
            &lt;Vendor&gt;string&lt;/Vendor&gt;
          &lt;/Classification&gt;
          &lt;Shipping&gt;
            &lt;FreightCarrier&gt;
              &lt;Name&gt;string&lt;/Name&gt;
            &lt;/FreightCarrier&gt;
            &lt;FreightService&gt;
              &lt;Description&gt;string&lt;/Description&gt;
            &lt;/FreightService&gt;
            &lt;FreightAccount&gt;
              &lt;SeqID&gt;int&lt;/SeqID&gt;
              &lt;Description&gt;string&lt;/Description&gt;
              &lt;FreightCarrier xsi:nil="true" /&gt;
              &lt;Person xsi:nil="true" /&gt;
              &lt;ThirdAcctNo&gt;string&lt;/ThirdAcctNo&gt;
              &lt;NonResident&gt;boolean&lt;/NonResident&gt;
            &lt;/FreightAccount&gt;
            &lt;ShippingOption&gt;
              &lt;Description&gt;string&lt;/Description&gt;
            &lt;/ShippingOption&gt;
            &lt;FreightCode&gt;string&lt;/FreightCode&gt;
            &lt;FreightCodeDescription&gt;string&lt;/FreightCodeDescription&gt;
            &lt;ShipComments&gt;string&lt;/ShipComments&gt;
            &lt;NeededBy&gt;string&lt;/NeededBy&gt;
            &lt;Rush&gt;boolean&lt;/Rush&gt;
            &lt;ReleaseDate&gt;dateTime&lt;/ReleaseDate&gt;
            &lt;ThirdPartyType&gt;int&lt;/ThirdPartyType&gt;
            &lt;ThirdAccountNumber&gt;string&lt;/ThirdAccountNumber&gt;
            &lt;NCShip&gt;boolean&lt;/NCShip&gt;
            &lt;NCPack&gt;boolean&lt;/NCPack&gt;
            &lt;NCOffers&gt;boolean&lt;/NCOffers&gt;
            &lt;NCHandling&gt;boolean&lt;/NCHandling&gt;
            &lt;NCOffShipHandling&gt;boolean&lt;/NCOffShipHandling&gt;
            &lt;NCSpecialHandling&gt;boolean&lt;/NCSpecialHandling&gt;
            &lt;NCRush&gt;boolean&lt;/NCRush&gt;
          &lt;/Shipping&gt;
          &lt;Money&gt;
            &lt;PriceClass&gt;
              &lt;SeqID&gt;int&lt;/SeqID&gt;
              &lt;Description&gt;string&lt;/Description&gt;
            &lt;/PriceClass&gt;
            &lt;ShippingHandlingCharge&gt;decimal&lt;/ShippingHandlingCharge&gt;
            &lt;RushHandlingCharge&gt;decimal&lt;/RushHandlingCharge&gt;
            &lt;NoChargeType&gt;
              &lt;Description&gt;string&lt;/Description&gt;
            &lt;/NoChargeType&gt;
            &lt;DiscountAmount&gt;decimal&lt;/DiscountAmount&gt;
            &lt;DiscountPercent&gt;float&lt;/DiscountPercent&gt;
            &lt;DiscountCode&gt;
              &lt;ID&gt;string&lt;/ID&gt;
              &lt;Description&gt;string&lt;/Description&gt;
            &lt;/DiscountCode&gt;
            &lt;Coupon&gt;
              &lt;Code&gt;string&lt;/Code&gt;
            &lt;/Coupon&gt;
            &lt;SpecialHandlingCharge&gt;decimal&lt;/SpecialHandlingCharge&gt;
            &lt;CreditAmount&gt;decimal&lt;/CreditAmount&gt;
            &lt;GiftCertificate&gt;
              &lt;UID&gt;string&lt;/UID&gt;
              &lt;Amount&gt;decimal&lt;/Amount&gt;
            &lt;/GiftCertificate&gt;
            &lt;GiftCertificateAmount&gt;decimal&lt;/GiftCertificateAmount&gt;
            &lt;TaxPercent&gt;decimal&lt;/TaxPercent&gt;
            &lt;NoChargeAmount&gt;decimal&lt;/NoChargeAmount&gt;
            &lt;TaxAmount&gt;decimal&lt;/TaxAmount&gt;
          &lt;/Money&gt;
          &lt;Payment&gt;
            &lt;PaymentType&gt;
              &lt;Description&gt;string&lt;/Description&gt;
              &lt;Sequence&gt;int&lt;/Sequence&gt;
            &lt;/PaymentType&gt;
            &lt;PaymentAmount&gt;decimal&lt;/PaymentAmount&gt;
            &lt;CCNumber&gt;string&lt;/CCNumber&gt;
            &lt;CCExpirationDate&gt;string&lt;/CCExpirationDate&gt;
            &lt;CSC&gt;string&lt;/CSC&gt;
            &lt;ARReference&gt;string&lt;/ARReference&gt;
          &lt;/Payment&gt;
          &lt;OrderVariables&gt;
            &lt;OrderVariable&gt;
              &lt;SeqID&gt;int&lt;/SeqID&gt;
              &lt;VariableField xsi:nil="true" /&gt;
              &lt;Value&gt;string&lt;/Value&gt;
            &lt;/OrderVariable&gt;
            &lt;OrderVariable&gt;
              &lt;SeqID&gt;int&lt;/SeqID&gt;
              &lt;VariableField xsi:nil="true" /&gt;
              &lt;Value&gt;string&lt;/Value&gt;
            &lt;/OrderVariable&gt;
          &lt;/OrderVariables&gt;
          &lt;OrderedBy&gt;
            &lt;ORDOBY&gt;
              &lt;SeqID&gt;int&lt;/SeqID&gt;
              &lt;CustomerID&gt;string&lt;/CustomerID&gt;
            &lt;/ORDOBY&gt;
            &lt;FullName&gt;string&lt;/FullName&gt;
            &lt;FullNameWithSuffix&gt;string&lt;/FullNameWithSuffix&gt;
            &lt;CityStateZip&gt;string&lt;/CityStateZip&gt;
            &lt;CityStateZipCountry&gt;string&lt;/CityStateZipCountry&gt;
            &lt;CompoundAddress&gt;string&lt;/CompoundAddress&gt;
          &lt;/OrderedBy&gt;
          &lt;ShipTo&gt;
            &lt;OrderShipTo&gt;
              &lt;SeqID&gt;int&lt;/SeqID&gt;
              &lt;Flag&gt;Other or OrderedBy&lt;/Flag&gt;
              &lt;Key&gt;string&lt;/Key&gt;
              &lt;NeededBy&gt;string&lt;/NeededBy&gt;
              &lt;ReleaseDate&gt;dateTime&lt;/ReleaseDate&gt;
              &lt;Rush&gt;boolean&lt;/Rush&gt;
              &lt;RushHandling&gt;decimal&lt;/RushHandling&gt;
              &lt;Comments&gt;string&lt;/Comments&gt;
              &lt;FreightCarrier xsi:nil="true" /&gt;
              &lt;FreightService xsi:nil="true" /&gt;
              &lt;ThirdPartyType&gt;int&lt;/ThirdPartyType&gt;
              &lt;ThirdPartyAccountNumber&gt;string&lt;/ThirdPartyAccountNumber&gt;
              &lt;FreightCode&gt;string&lt;/FreightCode&gt;
              &lt;FreightCodeDescription&gt;string&lt;/FreightCodeDescription&gt;
              &lt;SpecialHandling xsi:nil="true" /&gt;
              &lt;SpecialHandlingCharge&gt;decimal&lt;/SpecialHandlingCharge&gt;
              &lt;ShippingHandlingCharge&gt;decimal&lt;/ShippingHandlingCharge&gt;
              &lt;FullName&gt;string&lt;/FullName&gt;
              &lt;FullNameWithSuffix&gt;string&lt;/FullNameWithSuffix&gt;
              &lt;CityStateZip&gt;string&lt;/CityStateZip&gt;
              &lt;CityStateZipCountry&gt;string&lt;/CityStateZipCountry&gt;
              &lt;CompoundAddress&gt;string&lt;/CompoundAddress&gt;
              &lt;PickPacks xsi:nil="true" /&gt;
            &lt;/OrderShipTo&gt;
            &lt;OrderShipTo&gt;
              &lt;SeqID&gt;int&lt;/SeqID&gt;
              &lt;Flag&gt;Other or OrderedBy&lt;/Flag&gt;
              &lt;Key&gt;string&lt;/Key&gt;
              &lt;NeededBy&gt;string&lt;/NeededBy&gt;
              &lt;ReleaseDate&gt;dateTime&lt;/ReleaseDate&gt;
              &lt;Rush&gt;boolean&lt;/Rush&gt;
              &lt;RushHandling&gt;decimal&lt;/RushHandling&gt;
              &lt;Comments&gt;string&lt;/Comments&gt;
              &lt;FreightCarrier xsi:nil="true" /&gt;
              &lt;FreightService xsi:nil="true" /&gt;
              &lt;ThirdPartyType&gt;int&lt;/ThirdPartyType&gt;
              &lt;ThirdPartyAccountNumber&gt;string&lt;/ThirdPartyAccountNumber&gt;
              &lt;FreightCode&gt;string&lt;/FreightCode&gt;
              &lt;FreightCodeDescription&gt;string&lt;/FreightCodeDescription&gt;
              &lt;SpecialHandling xsi:nil="true" /&gt;
              &lt;SpecialHandlingCharge&gt;decimal&lt;/SpecialHandlingCharge&gt;
              &lt;ShippingHandlingCharge&gt;decimal&lt;/ShippingHandlingCharge&gt;
              &lt;FullName&gt;string&lt;/FullName&gt;
              &lt;FullNameWithSuffix&gt;string&lt;/FullNameWithSuffix&gt;
              &lt;CityStateZip&gt;string&lt;/CityStateZip&gt;
              &lt;CityStateZipCountry&gt;string&lt;/CityStateZipCountry&gt;
              &lt;CompoundAddress&gt;string&lt;/CompoundAddress&gt;
              &lt;PickPacks xsi:nil="true" /&gt;
            &lt;/OrderShipTo&gt;
          &lt;/ShipTo&gt;
          &lt;BillTo&gt;
            &lt;Flag&gt;Other or OrderedBy or DoNotUse or ShipTo&lt;/Flag&gt;
            &lt;FullName&gt;string&lt;/FullName&gt;
            &lt;FullNameWithSuffix&gt;string&lt;/FullNameWithSuffix&gt;
            &lt;CityStateZip&gt;string&lt;/CityStateZip&gt;
            &lt;CityStateZipCountry&gt;string&lt;/CityStateZipCountry&gt;
            &lt;CompoundAddress&gt;string&lt;/CompoundAddress&gt;
          &lt;/BillTo&gt;
          &lt;Offers&gt;
            &lt;OfferOrdered&gt;
              &lt;Offer xsi:nil="true" /&gt;
              &lt;Quantity&gt;int&lt;/Quantity&gt;
              &lt;CanceledQuantity&gt;int&lt;/CanceledQuantity&gt;
              &lt;OrderShipTo xsi:nil="true" /&gt;
              &lt;OrderShipToKey xsi:nil="true" /&gt;
              &lt;PriceType&gt;unsignedByte&lt;/PriceType&gt;
              &lt;UnitPrice&gt;decimal&lt;/UnitPrice&gt;
              &lt;ShipType&gt;short&lt;/ShipType&gt;
              &lt;ShippingHandling&gt;decimal&lt;/ShippingHandling&gt;
              &lt;Discounts&gt;decimal&lt;/Discounts&gt;
              &lt;DiscountPercent&gt;int&lt;/DiscountPercent&gt;
              &lt;DocumentID&gt;string&lt;/DocumentID&gt;
              &lt;SeqID&gt;int&lt;/SeqID&gt;
              &lt;CloneLine&gt;int&lt;/CloneLine&gt;
              &lt;Unapproved&gt;boolean&lt;/Unapproved&gt;
              &lt;ShipToKey&gt;string&lt;/ShipToKey&gt;
              &lt;FgnOrder&gt;string&lt;/FgnOrder&gt;
              &lt;Comments&gt;string&lt;/Comments&gt;
              &lt;RCOrderKey&gt;string&lt;/RCOrderKey&gt;
              &lt;Recurring&gt;boolean&lt;/Recurring&gt;
              &lt;LineNumber&gt;int&lt;/LineNumber&gt;
              &lt;Variables xsi:nil="true" /&gt;
              &lt;ProductDetails xsi:nil="true" /&gt;
            &lt;/OfferOrdered&gt;
            &lt;OfferOrdered&gt;
              &lt;Offer xsi:nil="true" /&gt;
              &lt;Quantity&gt;int&lt;/Quantity&gt;
              &lt;CanceledQuantity&gt;int&lt;/CanceledQuantity&gt;
              &lt;OrderShipTo xsi:nil="true" /&gt;
              &lt;OrderShipToKey xsi:nil="true" /&gt;
              &lt;PriceType&gt;unsignedByte&lt;/PriceType&gt;
              &lt;UnitPrice&gt;decimal&lt;/UnitPrice&gt;
              &lt;ShipType&gt;short&lt;/ShipType&gt;
              &lt;ShippingHandling&gt;decimal&lt;/ShippingHandling&gt;
              &lt;Discounts&gt;decimal&lt;/Discounts&gt;
              &lt;DiscountPercent&gt;int&lt;/DiscountPercent&gt;
              &lt;DocumentID&gt;string&lt;/DocumentID&gt;
              &lt;SeqID&gt;int&lt;/SeqID&gt;
              &lt;CloneLine&gt;int&lt;/CloneLine&gt;
              &lt;Unapproved&gt;boolean&lt;/Unapproved&gt;
              &lt;ShipToKey&gt;string&lt;/ShipToKey&gt;
              &lt;FgnOrder&gt;string&lt;/FgnOrder&gt;
              &lt;Comments&gt;string&lt;/Comments&gt;
              &lt;RCOrderKey&gt;string&lt;/RCOrderKey&gt;
              &lt;Recurring&gt;boolean&lt;/Recurring&gt;
              &lt;LineNumber&gt;int&lt;/LineNumber&gt;
              &lt;Variables xsi:nil="true" /&gt;
              &lt;ProductDetails xsi:nil="true" /&gt;
            &lt;/OfferOrdered&gt;
          &lt;/Offers&gt;
          &lt;OrderRecurrenceSchedule&gt;
            &lt;RecurrenceSchedules&gt;
              &lt;SeqID&gt;int&lt;/SeqID&gt;
              &lt;ID&gt;string&lt;/ID&gt;
              &lt;Description&gt;string&lt;/Description&gt;
              &lt;Definition&gt;string&lt;/Definition&gt;
              &lt;DefinitionDetail&gt;string&lt;/DefinitionDetail&gt;
              &lt;Schedule&gt;EveryXDays or EveryXWeeks or EveryXMonths&lt;/Schedule&gt;
              &lt;ScheduleCount&gt;int&lt;/ScheduleCount&gt;
              &lt;Cycle&gt;Rolling or Custom&lt;/Cycle&gt;
              &lt;StartCycleDate&gt;dateTime&lt;/StartCycleDate&gt;
              &lt;DaysToJoin&gt;int&lt;/DaysToJoin&gt;
              &lt;MonthlyRecurrenceType&gt;DayOfMonth or WeekOfMonthAndDayOfWeek&lt;/MonthlyRecurrenceType&gt;
              &lt;MinimumRecurrences&gt;int&lt;/MinimumRecurrences&gt;
              &lt;MaximumRecurrences&gt;int&lt;/MaximumRecurrences&gt;
              &lt;RecurrenceIncrement&gt;int&lt;/RecurrenceIncrement&gt;
              &lt;AllowInfiniteRecurrence&gt;boolean&lt;/AllowInfiniteRecurrence&gt;
              &lt;InfiniteTag&gt;string&lt;/InfiniteTag&gt;
              &lt;DurationTag&gt;string&lt;/DurationTag&gt;
              &lt;ExpirationDate&gt;dateTime&lt;/ExpirationDate&gt;
              &lt;NextCycleDate&gt;dateTime&lt;/NextCycleDate&gt;
              &lt;HasValidCycleDate&gt;boolean&lt;/HasValidCycleDate&gt;
              &lt;AnyOffer&gt;boolean&lt;/AnyOffer&gt;
              &lt;RecurrenceScheduleShippingOptions xsi:nil="true" /&gt;
            &lt;/RecurrenceSchedules&gt;
            &lt;RecurrenceOfferFlag&gt;boolean&lt;/RecurrenceOfferFlag&gt;
            &lt;RecurrenceShippingOption&gt;
              &lt;Description&gt;string&lt;/Description&gt;
            &lt;/RecurrenceShippingOption&gt;
            &lt;RecurrenceSpecialHandlingCharge&gt;decimal&lt;/RecurrenceSpecialHandlingCharge&gt;
            &lt;NumberRecurrence&gt;int&lt;/NumberRecurrence&gt;
          &lt;/OrderRecurrenceSchedule&gt;
          &lt;OrderBudget&gt;
            &lt;Person&gt;
              &lt;Name xsi:nil="true" /&gt;
              &lt;CompanyInfo xsi:nil="true" /&gt;
              &lt;Address xsi:nil="true" /&gt;
              &lt;ContactInfo xsi:nil="true" /&gt;
              &lt;BillingInfo xsi:nil="true" /&gt;
              &lt;Variables xsi:nil="true" /&gt;
            &lt;/Person&gt;
          &lt;/OrderBudget&gt;
        &lt;/order&gt;
      &lt;/AddOrder&gt;
    &lt;/soap:Body&gt;
  &lt;/soap:Envelope&gt;
  HTTP/1.1 200 OK
  Content-Type: text/xml; charset=utf-8
  Content-Length: length
  
  &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;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/"&gt;
    &lt;soap:Header&gt;
      &lt;DebugHeader xmlns="http://sma-promail/"&gt;
        &lt;Debug&gt;boolean&lt;/Debug&gt;
        &lt;Request&gt;string&lt;/Request&gt;
      &lt;/DebugHeader&gt;
    &lt;/soap:Header&gt;
    &lt;soap:Body&gt;
      &lt;AddOrderResponse xmlns="http://sma-promail/"&gt;
        &lt;AddOrderResult&gt;
          &lt;OrderSeqID&gt;int&lt;/OrderSeqID&gt;
          &lt;OrderID&gt;string&lt;/OrderID&gt;
        &lt;/AddOrderResult&gt;
      &lt;/AddOrderResponse&gt;
    &lt;/soap:Body&gt;
  &lt;/soap:Envelope&gt;
  </code></pre>