Last active
November 30, 2019 17:22
-
-
Save yudegaki/df7c844229c70add6df137f86f0e2c08 to your computer and use it in GitHub Desktop.
This file contains 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
import json,os,base64 | |
import urllib.request | |
from flask_cors import CORS,cross_origin | |
from flask import Flask,request,abort,jsonify | |
#POSTするURL設定 | |
method = 'POST' | |
url = 'https://hogehoge' | |
headers = {'Content-Type' : 'application/json'} | |
#Access-Control-Allow-Originヘッダを追加 | |
app = Flask(__name__) | |
cors = CORS(app) | |
@app.route('/',methods = ["GET","POST"]) | |
@cross_origin() | |
def main(): | |
if request.method == 'GET': | |
#URLエンコードで受け取った文字列をdecode | |
req_url = urllib.parse.unquote(request.args.get('url')) | |
req_get = urllib.request.Request(req_url,method = 'GET') | |
with urllib.request.urlopen(req_get) as response : | |
return response.read() | |
else : | |
今回は = '省略' + 'します' | |
if __name__ == '__main__': | |
port = int(os.getenv("PORT", 5000)) | |
app.run(host="0.0.0.0", port=port) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment