通过xml文件向webservice发送请求



我有一个在"tcs-webdev2:8200/scheduler/requestgroup"上运行的Web服务,可以使用xml文件(下面的示例xml文件)向其发送新的构建请求。我需要一些指导关于如何通过xml文件向webserive发出请求。

示例xml文件:-

<BuildInfo>
    <BuildSource>DEV_CI</BuildSource> 
    <SoftwareProductBuild>MAAAAANLGD0000211.1_101</SoftwareProductBuild>
    <PriorrootBuild>MAAAAANLGD0000211.1</PriorrootBuild>
    <NewSIBuilds>
        <Image>
            <Type>LNX</Type>
            <SoftwareImageBuild>buildlocation</SoftwareImageBuild>
            <Location>\severbuildlocationcheckout</Location>
            <Variant>Default</Variant>
            <LoadType>Debug</LoadType>
        </Image>
    </NewSIBuilds>
</BuildInfo>

这取决于您的web服务,以及您需要如何发送请求,但您必须执行以下操作:

import httplib
with open("your_xml_filename.xml") as f:
    body = f.read()
headers = {"Content-type": "application/xml"}
conn = httplib.HTTPConnection("tcs-webdev2", 8200)
conn.request("POST", "/scheduler/requestgroup", body, headers)
response = conn.getresponse()
print( response.status )
print( response.read())
conn.close()

它假设tcs-webdev2是一个有效的主机名(如果不是,则可以使用IP地址)。此外,此请求是HTTPPOST,您的服务可能需要不同的请求类型。此外,可能还需要一些额外的标头和身份验证。

最新更新