Skip to content

Instantly share code, notes, and snippets.

@shouhei
Last active August 29, 2015 14:05
Show Gist options
  • Select an option

  • Save shouhei/546ec905411d8b80bffe to your computer and use it in GitHub Desktop.

Select an option

Save shouhei/546ec905411d8b80bffe to your computer and use it in GitHub Desktop.
jsonをパースしてpostするやーつ
# 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