我的React应用程序中有此方法
export async function createUser(state) {
const url = "http://localhost:8080";
console.log("Sending request");
const response = await axios.post(url, {
t: "create",
email: state.email,
password: state.password,
username: state.username,
phone: state.phone,
morada: state.morada,
postCode: state.postCode
});
return String(response.data);
}
我已经在Visual Studio中运行了
private void Listen() {
listener = new HttpListener();
listener.Prefixes.Add("http://localhost:" + port.ToString() + "/");
listener.Start();
while (true) {
try {
HttpListenerContext context = listener.GetContext();
Process(context);
}
catch (Exception ex) {
Console.WriteLine(ex.ToString());
}
}
}
private void Process(HttpListenerContext context) {
var data_text = new StreamReader(context.Request.InputStream,
context.Request.ContentEncoding).ReadToEnd();
Console.WriteLine(data_text);
}
对于GET请求,我可以正常使用。现在我想做一个POST,我得到的只是空白空间。 根据我在互联网上可以找到的信息,这就是从POST请求中获取数据的方式,但我什么也没得到。 任何帮助将不胜感激