problem description
try to do a hands-on project after learning the Flask framework. The function is to collect and use the hash decryption API exposed on the network to obtain plaintext
when the server data is obtained through jQuery.get (), it is found that the returned data size is 0 bytes, but it is normal to open the URL directly through the browser.
the environmental background of the problems and what methods you have tried
Google tried round and round without solving the problem. Many people say that it is cross-domain, but it must be under a domain name. There are different opinions on the solution, and I feel confused.
in fact, I have implemented the exact same function in Laravel before, and it was quite smooth at that time, so I thought there was something wrong with writing the back-end code (just guessing that), emmm seemed to be written in native JS before, but I don"t remember.
related codes
main.py (Flask)
import requests
from flask import Flask, request, render_template
app = Flask(__name__)
@app.route("/")
def index():
return render_template("index.html")
@app.route("/decrypt")
def decrypt():
payload = {"hash": request.args.get("hash"), "hash_type": "md5", "email": "jayan2358@protonmail.com",
"code": "1vds464vxc61v"}
r = requests.get("http://md5decrypt.net/en/Api/api.php", params=payload)
return r.text
if __name__ == "__main__":
app.run()
< hr >
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>CHash</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/css/bootstrap.min.css">
</head>
<body>
<nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark">
<a class="navbar-brand" href="-sharp">CHash</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="-sharpnavbarCollapse">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="-sharp">Home</a>
</li>
</ul>
<form class="form-inline mt-2 mt-md-0">
<input id="hash" name="hash" class="form-control mr-sm-2" type="text" placeholder="Enter Hash">
<button id="decrypt" class="btn btn-outline-success my-2 my-sm-0">Decrypt</button>
</form>
</div>
</nav>
<script src="https://cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1/dist/umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/js/bootstrap.min.js"></script>
<script src="../static/main.js"></script>
</body>
</html>
static/main.js
$("-sharpdecrypt").click(function () {
$.get("/decrypt", {hash: $("-sharphash").val()}, function (data) {
alert(data);
})
}
);
what result do you expect? What is the error message actually seen?
Mengxin asks for advice. I hope to give you a solution and also briefly explain the reason for reporting an error.
Chrome DevTools grabbed a packet Ajax request and reported a Provisional headers are shown error. The screenshot is below, and Response is empty, so do not cut off