传递数据curl django

时间:2013-10-16 18:49:44

标签: django curl

我需要通过POST发送数据。有这个例子,但不知道如何在django中这样做。有人可以帮忙吗

示例:

curl https://ws.pagseguro.uol.com.br/v2/checkout/ -d\
    "email=suporte@lojamodelo.com.br\
    &token=95112EE828D94278BD394E91C4388F20\
    &currency=BRL\
    &itemId1=0001\
    &itemDescription1=Notebook Prata\
    &itemAmount1=24300.00\
    &itemQuantity1=1\
    &itemWeight1=1000\
    &itemId2=0002\
    &itemDescription2=Notebook Rosa\
    &itemAmount2=25600.00\
    &itemQuantity2=2\
    &itemWeight2=750\
    &reference=REF1234\
    &senderName=Jose Comprador\
    &senderAreaCode=11\
    &senderPhone=56273440\
    &senderEmail=comprador@uol.com.br\
    &shippingType=1\
    &shippingAddressStreet=Av. Brig. Faria Lima\
    &shippingAddressNumber=1384\
    &shippingAddressComplement=5o andar\
    &shippingAddressDistrict=Jardim Paulistano\
    &shippingAddressPostalCode=01452002\
    &shippingAddressCity=Sao Paulo\
    &shippingAddressState=SP\
    &shippingAddressCountry=BRA"

1 个答案:

答案 0 :(得分:1)

你可能想看看请求库,但是一个简单的POST不需要比python中内置的更多:

import urllib
import urllib2
data = urllib.urlencode({"email":"suporte@lojamodelo.com.br","token":...})
req = urllib2.Request("https://ws.pagseguro.uol.com.br/v2/checkout/", data)
response = urllib2.urlopen(req)