通过xml文件向webservice发送请求?

2024-04-26 06:07:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个运行在"tcs-webdev2:8200/scheduler/requestgroup"的webservice,可以使用xml文件(下面的示例xml文件)向其发送新的构建请求。我需要一些指导 通过nxml文件对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>\\\sever\buildlocation\checkout</Location>
            <Variant>Default</Variant>
            <LoadType>Debug</LoadType>
        </Image>
    </NewSIBuilds>
</BuildInfo>

Tags: 文件image示例typelocationxmlvariantbuildlocation
1条回答
网友
1楼 · 发布于 2024-04-26 06:07:06

这取决于您的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,您的服务可能需要不同的请求类型。此外,可能还需要一些附加的头和身份验证。在

相关问题 更多 >