Last active
July 27, 2020 15:19
-
-
Save nenodias/7ed727460675a4ed791b to your computer and use it in GitHub Desktop.
Python Socket Soap Call
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# *-* coding:utf-8 *-* | |
import os | |
import socket | |
target_host = "www.webservicex.com" | |
target_port = 80 | |
target_path = "/globalweather.asmx" | |
target_namespace = "http://www.webserviceX.NET" | |
service = "GetCitiesByCountry" | |
xmldata = ""; | |
xmldata += '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://www.webserviceX.NET">' | |
xmldata += '<soapenv:Header/>' | |
xmldata += '<soapenv:Body>' | |
xmldata += '<web:GetCitiesByCountry>' | |
xmldata += '<web:CountryName>Argentina</web:CountryName>' | |
xmldata += '</web:GetCitiesByCountry>' | |
xmldata += '</soapenv:Body>' | |
xmldata += '</soapenv:Envelope>' | |
tamanho = len(xmldata ) | |
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
client.connect( (target_host, target_port) ) | |
chamada = ''' | |
POST http://{host}/{path} HTTP/1.1 | |
Content-Type: text/xml;charset=UTF-8 | |
SOAPAction: "{namespace}/{service}" | |
Content-Length: {tamanho} | |
Host: {host} | |
Connection: Keep-Alive | |
{xml} | |
'''.format(host = target_host, path = target_path, namespace = target_namespace, service = service, xml = xmldata, tamanho = tamanho) | |
if bytes != str: # Testing if is python2 or python3 | |
chamada = bytes(chamada, 'utf-8') | |
client.send(chamada) | |
response = client.recv(4096) | |
response = response.decode(encoding="utf-8") | |
response = response.replace("<","<") | |
response = response.replace(">",">") | |
print( response ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment