如何用python发布post并接收XML

2024-05-14 14:35:04 发布

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

除了分配给我的这项任务外,我对python一无所知。目前我是WebClient,使用get字符串接收XML返回,但我需要使用POST。在

我需要写一篇文章,然后再读回XML,我当前的代码:

    postUrl = 'http://sitetopost.net/checkduplicateemail?TransactionType=NoCharge&CampaignId=47750&SubCampaignId=6010117&BundleId=' + bundleId + '&PackageDealId=' + packageDealId + '&OrganizationId=e11b4f9e-be9a-464f-96b0-885a571e3cc9&FirstName=' + firstName + '&LastName=' + lastName + '&EmailAddress=' + email + '&Phone=' + phone + '&IPAddress=[=$Registration.IpAddress=]&Address1=' + address + '&Address2=' + address2 + '&City=' + city + '&ProvinceAbbreviation=' + state + '&PostalCode=' + postalcode + '&order_OriginatorId=6&order_OriginatorOrderIdentifier=1234567&userinfo_ProductWebUserName=&userinfo_ProductWebUserPassword='

contentTemplate = Sel.GetHtmlContentTemplateHtmlByName(path.Meme, contentPage)

    client = WebClient()
    billResponse = client.DownloadString(postUrl)
    xml = XElement.Parse(billResponse)

    Logger.Trace("XML: {0}", billResponse)

我怎样才能把这个改成帖子?谢谢!在


Tags: 字符串代码clienthttpgetnet文章order
1条回答
网友
1楼 · 发布于 2024-05-14 14:35:04

在python中,请求库是一种很好的方法。非常简单:

import requests

url = #relevant url
data = #{some dictionary}
response = requests.post(url, data=data)

然后你可以做任何你想做的回应。请尝试拨打以下电话以查看它的功能:

^{pr2}$

相关问题 更多 >

    热门问题