ich hab folgendes Problem, ich habe eine dotNet Webanwendung die per SOAP angesprochen werden soll, als Vorlage habe ich mit Wireshark (Netzwerksniffer)
die Verbindung des Originalprogramms belauscht und will diese nun nachbauen. Geht soweit auch fast gut.
Ich hab mittels httplib folgenden Code zusammengebastelt:
Code: Alles auswählen
#!/usr/bin/env python
import httplib
logincred='''<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<Login xmlns="http://blabla.de/">
<username>blablabla</username>
<password>blablabla</password>
</Login>
</soap:Body>
</soap:Envelope>'''
webservice = httplib.HTTP("blablabla.de")
webservice.debuglevel=1
webservice.putrequest('POST','/blablabla_mgmt.asmx')
webservice.putheader('User-Agent','Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol 2.0.50727.3615')
webservice.putheader('Content-Type','text/xml; charset=utf-8')
webservice.putheader('SOAPAction','"http://blablabla.de/Login"')
webservice.putheader('Host','blablabla')
webservice.putheader('Connection','Keep-Alive')
webservice.putheader('Expect','100-continue')
webservice.putheader('Content-Length',"%d" % len(logincred))
webservice.endheaders()
webservice.send(logincred)
statuscode, statusmessage, header = webservice.getreply()
print "Response: ", statuscode, statusmessage
print "headers: ", header
res = webservice.getfile().read()
print res
Ich brauch das Keep-Alive aber, da ich als Antwort einen Sessioncookie bekomme um weitere Anfragen starten zu können.
Nehme ich das Keep_alive raus, bekomme ich meine Antwort wie sie sein soll, nur schließt er dann direkt wie Verbindung wieder!
Dann hab ich gegoogelt und gefunden, dass httplib2 mit Keep-Alive umgehen kann. also habe ich folgendes gebastelt:
Code: Alles auswählen
#!/usr/bin/env python
import httplib2
logincred='''<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<Login xmlns="http://blablabla.de/">
<username>blablabla</username>
<password>blablabla</password>
</Login>
</soap:Body>
</soap:Envelope>'''
#Variablen
URL="http://blablabla.de/"
headers={}
headers['User-Agent']='Mozilla/4.0 (compatible; MSIE 6.0; MS Web Services Client Protocol 2.0.50727.3615)'
headers['Content-Type']='text/xml; charset=utf-8'
headers['SOAPAction']='"http://blablabla.de/Login"'
headers['Host']='blablabla.de'
headers['Connection']='Keep-Alive'
headers['Expect']='100-continue'
headers['Content-Length']='%d' % len(logincred)
#print headers
webservice = httplib2.Http()
resp, content = webservice.request(URL,"POST /blablabla_mgmt.asmx",body=logincred,headers=headers)
print "Response: \t", resp
print "\n\ncontent: \t", content
Wenn ich mir mit Wireshark nun den Verbindungsversuch von:
- Original client
- httplib client
- httplib2 client
- Original client
Verbindungstyp HTTP/1.1
Div Header - httplib client
Verbindungstyp HTTP/1.0
Selbe Header wie bei Original - httplib2 client
Hier werden die Header aber plötzlich klein geschrieben z.b anstatt
SOAPAction: "http://blablablad.de/Login"\r\n
soapaction: "http://blablabla.de/Login"\r\n
Sie stehen in anderer Reihenfolge als ich sie angegeben habe und es ist noch ein Header hinzugefügt worden und zwar:
Accept-Encoding: identity
Sonst ist auch hier alles gleich (nur halt klein geschrieben)
Hat jemand ne Idee wie ich weitermachen soll?
Gibt es ne Möglichkeit das der HTTPlib Client mit dem Keep-Alive umgehen kann, bzw was mach ich beim HTTPlib2 Client falsch?
Wäre für jede Hilfe dankbar!
Gruß hardez