我正在发布一个数组
$name[0] = "anurag";
$name[1] = "abhishek";
$ch = curl_init('http://localhost:8000/v0/url-generator');
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, "name=$name");
curl_exec ($ch);
curl_close ($ch);
在python中,我得到了name=array。
if request.method == 'POST':
name = request.POST["name"]
print name
output=数组。
我想在python中输出这个:
name = ['anurag','abhishek']
在PHP中实现$name,以便向curl请求发送字符串,而不是数组
http://PHP.net/implode
然后在python中拆分值。或者使用json数组
首次使用json_encode($name)
将该值发送到python程序
如果你正在发送REST主体,那么在python端你可以像一样尝试
try:
body = self.request.body
body_loads = loads(body)
except Exception as e:
LOG_WARNING('Exception: %s', str(e))
return WebReturn(self,httplib.FORBIDDEN, {'reason':'Body is not Define '},{'data':"Msg"})
get = None
get = dict2obj(body_loads)
这是的格言2
def dict2obj(d):
if isinstance(d, list):
d = [dict2obj(x) for x in d]
if not isinstance(d, dict):
return d
class C(object):
pass
o = C()
for k in d:
o.__dict__[k] = dict2obj(d[k])
return o
Hpe这将帮助您