-1

私のコードでは、javascript XML HTTP Post リクエストから空の不変辞書を取得し続けています。リクエストを送信する JavaScript は次のとおりです (javascript):

xhr = new XMLHttpRequest();
xhr.open("POST", "https://webpage-hoster--lovethebears1o1.repl.co/save", true)
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(JSON.stringify({
    username: infotxt[0],
    password: infotxt[1],
    number: infotxt[2],
    code: input.value,
    name: titleBox.value
}));

パイソン:

@app.route("/save", methods=["POST"])
def save():
  try:
    print(str(request.form))
    username = str(request.form["username"])
    pword = str(request.form["password"])
    number = int(request.form["number"])
    code = str(request.form["code"])
    name = str(request.form["name"])
  except Exception as e:
    print("error-1-" + str(e))
    return "error"
return "success"

これを実行すると、出力に次のように表示されます。

ImmutableMultiDict([])
error-1-400 Bad Request: The browser (or proxy) sent a request that this server could not understand.

送信時に値が含まれていても、サーバーはそれを空の辞書と見なしています。

4

1 に答える 1