开发者

The data format for post in urllib2.Request

开发者 https://www.devze.com 2022-12-22 09:27 出处:网络
What should data look like before data encoding in: urllib2.Request(someurl,data)I tried [(\'name1\',\'value1\'),(\'name2\',\'value2\'),...]but not work.:(

What should data look like before data encoding in: urllib2.Request(someurl,data) I tried [('name1','value1'),('name2','value2'),...]but not work.:(

EDIT: I made a log in the program and recorded the value of urllib.urlencode(data):

content=%E5%8F%91%E5%B8%83%E4%BA%86%E4%B8%80%E4%B8%AA%E6%96%B0%E4%B8%BB%E9%A2%98%EF开发者_StackOverflow社区%BC%9A%3Ca+href%3D%27http%3A%2F%2Fbbs.jianshe99.com%2Fforum-5-195%2Ftopic-448618.html%27+target%3D%27_blank%27%3E+fsdfdsf%3C%2Fa%3E

then post it to a php script which is

<?php
print_r($_POST);
?>

but always get a response as:

array()


data may be a string specifying additional data to send to the server, or None if no such data is needed. Currently HTTP requests are the only ones that use data; the HTTP request will be a POST instead of a GET when the data parameter is provided. data should be a buffer in the standard application/x-www-form-urlencoded format. The urllib.urlencode() function takes a mapping or sequence of 2-tuples and returns a string in this format.

See Also

  • urllib2.Request
0

精彩评论

暂无评论...
验证码 换一张
取 消