如何使用python发布帖子并接收XML

时间:2013-07-10 13:13:19

标签: python xml

我对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)

如何将其更改为帖子?谢谢!

1 个答案:

答案 0 :(得分:3)

请求库是在python中执行此操作的绝佳方式。非常简单:

import requests

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

然后你可以用响应做任何你想做的事。尝试调用以下内容以查看其内容:

dir(response)
vars(response)