랭귀지/python
Python3 urllib으로 http로 POST 전송
유키공
2019. 12. 21. 11:43
Python3 urllib으로 http로 POST 전송
''' Created on 2019. 12. 21. @author: test ''' import urllib.parse import urllib.request details = urllib.parse.urlencode({'CODE': '코드', 'NAME': '이름', 'KIND': '종류', 'PRICE': '가격', 'USERID': '아이디'}) details = details.encode('UTF-8') url = urllib.request.Request('https://test.cafe24.com/postdata_test.php', details) url.add_header("User-Agent","Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.2.149.29 Safari/525.13") ResponseData = urllib.request.urlopen(url).read().decode("utf-8") print(ResponseData).add_header 함수를 사용해 헤더를 추가할 수도 있습니다.