0

我对python一无所知,但这项任务已分配给我。目前我是 WebClient 并使用获取字符串来接收 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)

我怎样才能把它变成一个帖子?谢谢!

4

1 回答 1

3

requests 库是在 python 中执行此操作的好方法。很简单:

import requests

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

然后你可以对响应做任何你想做的事情。尝试调用以下命令以查看它有什么:

dir(response)
vars(response)
于 2013-07-10T13:17:14.297 回答