Transitioning from system.net.httpPost() to system.net.httpClient()

Due to httpPost() being deprecated in the future I’m attempting to transition a working SOAP interface to httpClient() as suggested in a number of discussions. I attempted to view differences in the frame on the wire and found that my post isn’t making it to the wire due to http error 415 “Unsupported Media Type”. All my headers seem to be the same and body is absolutely the same. Not quite sure what attributes would cause the 415 now that I’m using httpClient(). There weren’t any SOAP based examples that I could find using the system.net.httpClient() function.

My data element is an XML string. If I eliminate the data element the request goes out on the wire but obviously fails with no payload. So I’m assuming there is something wrong with my method of identifying the content-type.



dataservice = 'http://cwa112300q:50211/TTPMESWS'

soapenv = """<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:laetus.com:ws:tts:mes">
   <soapenv:Header/>
   <soapenv:Body>
      <urn:SetMaterial>
         <Identifier>KRD302</Identifier>
         <Description>KRD Material 302</Description>
         <TargetLevel>Carton</TargetLevel>
         <Item>
            <Identifier>302</Identifier>
            <Description>Product 302</Description>
            <Level>Carton</Level>
            <Action>C</Action>
         </Item>
      </urn:SetMaterial>
   </soapenv:Body>
</soapenv:Envelope>"""

myheaders = {
        'SOAPAction': 'SetMaterial',
        'Context-type' : 'text/xml;charset=UTF-8'
}

try:
	client = system.net.httpClient()
	response = client.post(url=dataservice,headers=myheaders,data=soapenv,username=user,password=pwd)

Should probably be Content-type, no?

I wish those trees would get out of the way so I could see the forest. Sigh…
Good catch. Don’t know how I managed that.
Thank you!

1 Like