Last active
August 29, 2015 14:05
-
-
Save shouhei/546ec905411d8b80bffe to your computer and use it in GitHub Desktop.
jsonをパースしてpostするやーつ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # coding:utf-8 | |
| import urllib | |
| import urllib2 | |
| import json | |
| import sys | |
| args = sys.argv | |
| argc = len(args) | |
| if (argc != 3): | |
| print 'Usage: arg is url and filename' | |
| quit(); | |
| url = args[1] | |
| print url | |
| params = json.load(open(args[2])) | |
| print params | |
| params = urllib.urlencode(params) | |
| req = urllib2.Request(url) | |
| # ヘッダ追加 | |
| req.add_header('Content-Type', 'application/x-www-form-urlencoded') | |
| # パラメータ追加 | |
| req.add_data(params) | |
| res = urllib2.urlopen(req) | |
| # レスポンス取得 | |
| body = res.read() | |
| print body |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment