我想知道Intersango API(文檔記錄不完整)的正確URL格式。我在C#編程我的客戶,但我看Python example和我有點困惑,什麼是真正被放置在請求主體:如何向Intersango API發送請求
def make_request(self,call_name,params):
params.append(('api_key',self.api_key)) // <-- How does this get serialized?
body = urllib.urlencode(params)
self.connect()
try:
self.connection.putrequest('POST','/api/authenticated/v'+self.version+'/'+call_name+'.php')
self.connection.putheader('Connection','Keep-Alive')
self.connection.putheader('Keep-Alive','30')
self.connection.putheader('Content-type','application/x-www-form-urlencoded')
self.connection.putheader('Content-length',len(body))
self.connection.endheaders()
self.connection.send(body)
response = self.connection.getresponse()
return json.load(response)
//...
我想不通出這段代碼:params.append(('api_key',self.api_key))
它是某種字典,它被序列化爲JSON,逗號分隔或者它是如何被序列化的?當參數被編碼並分配給它時,身體會是什麼樣子?
P.S.我沒有任何可以運行代碼的東西,所以我可以調試它,但是我只是希望這足夠簡單,可以理解知道Python的人,並且他們能夠告訴我該線路上發生了什麼的代碼。
你能夠使它發揮作用?我遵循相同的步驟,但根本無法獲得經過身份驗證的API工作,得到{「遠程服務器返回錯誤:(417)期望失敗。」} – galets 2012-06-20 04:01:55