如何编码POST的连字符

时间:2016-10-18 14:28:11

标签: python post

我想向API发送POST请求。

API参数

api = {
 'url': 'test.com',
 'path': 'myapi.cgi',
 'port': 443,
 'method': 'POST',
 'params': {
   'o': 'my-org',
   'i': '322e9c5eefd1953f788bdefdd7e627d1_bb604d924aefdd7c25b14a382dea3585'
 }
}

我发送这样的HTTPS请求:

conn = httplib.HTTPSConnection(self.api['url'], self.api['port'], timeout=5, context=httplib.ssl._create_unverified_context())
conn.request(self.api['method'], self.api['path'], urllib.urlencode(self.api['params']), headers)

在这里,我使用urlencode对参数进行编码。

我收到了API的回复:Invalid chars in organization。 当我使用没有连字符的组织名称时,调用工作。所以,我猜问题是- char。

如何正确编码my-org字? -是POST请求的合法字符,也许我不需要对其进行编码?

我无法访问API源代码。

0 个答案:

没有答案