Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const req_url = 'http://localhost:5000/'
- let resp = fetch(req_url, {
- method: 'POST',
- mode: 'no-cors',
- headers: new Headers({
- 'Authorization' : 'Basic dXNlcjpwd2Q=', // user:pwd
- }),
- }).then((resp) => resp)
- // или так
- let headers = new Headers()
- headers.append('Authorization', 'Basic Y2lhdDpwd2Q=')
- let resp = fetch(req_url, {
- method: 'POST',
- mode: 'no-cors',
- headers: headers,
- credentials: 'include'
- }).then((resp) => resp)
- // или даже так
- let headers = new Headers()
- headers.append('Authorization', 'Basic Y2lhdDpwd2Q=')
- let resp = fetch(req_url, {
- method: 'POST',
- mode: 'no-cors',
- headers: headers,
- credentials: 'include'
- }).then((resp) => resp)
- #!/usr/bin/env python3
- from functools import wraps
- from flask import Flask, request, Response
- app = Flask(__name__)
- def check_auth(username, password):
- return username == 'user' and password == 'pwd'
- def authenticate():
- return Response(
- 'Could not verify your access level for that URL.n'
- 'You have to login with proper credentials', 401,
- {'WWW-Authenticate': 'Basic realm="Login Required"'})
- def requires_auth(f):
- @wraps(f)
- def decorated(*args, **kwargs):
- auth = request.authorization
- if not auth or not check_auth(auth.username, auth.password):
- return authenticate()
- return f(*args, **kwargs)
- return decorated
- @app.route('/', methods=['POST', 'GET'])
- @requires_auth
- def secret_page():
- return """
- <!doctype HTML>
- <html>
- <head></head>
- <body><h1>Success!</h1></body>
- </html>
- """
- if __name__ == '__main__':
- app.run(debug=True)
- const req_url = 'http://localhost:5000/'
- let resp = fetch(req_url, {
- method: 'POST',
- mode: 'no-cors',
- headers: {
- 'Authorization' : 'Basic dXNlcjpwd2Q=',
- },
- }).then((resp) => resp)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement