post改为json方式

main
wuyize 2023-07-01 15:01:36 +08:00
parent 069c3013e9
commit c58f251953
4 changed files with 52 additions and 22 deletions

View File

@ -30,7 +30,7 @@ AppFluWindow {
} }
} }
Rectangle{ Rectangle {
width: parent.width * 0.5 width: parent.width * 0.5
height: parent.height height: parent.height
color: "#f3f3f3" color: "#f3f3f3"
@ -91,28 +91,30 @@ AppFluWindow {
//normalColor: "#ffffff" //normalColor: "#ffffff"
text: "登录" text: "登录"
onClicked: { onClicked: {
var param ={ var param = {
username: account.text, "username": account.text,
password: password.text "password": password.text
} }
Request.post("login",JSON.toString(param), function(result, data) { Request.post("login",
console.log(result) JSON.stringify(param),
console.log(data) function (result, data) {
FluApp.navigate("/"); console.log(result)
window.close(); console.log(data)
}, function() { FluApp.navigate("/")
FluApp.navigate("/"); window.close()
window.close(); }, function (p1, p2) {
}) console.log(p1)
console.log(p2)
//FluApp.navigate("/");
//window.close();
})
//HttpClient.doGetRequest( //HttpClient.doGetRequest(
// "https://quic.aiortc.org/", // "https://quic.aiortc.org/",
// loginItem, "login") // loginItem, "login")
} }
} }
} }
} }
// FluPivotItem { // FluPivotItem {
@ -125,6 +127,5 @@ AppFluWindow {
} }
} }
} }
} }
} }

View File

@ -122,6 +122,20 @@ FluWindow {
title_bar.maximizeButton.visible = true title_bar.maximizeButton.visible = true
// window.backgroundVisible = false // window.backgroundVisible = false
window.show() window.show()
Request.post(
"knowledge/file", "{\n"
+ " \"name\": \"特东局却热\",\n" + " \"brief\": \"fugiat occaecat\",\n"
+ " \"size\": 88,\n" + " \"sha256\": \"ea incididunt pariatur\",\n"
+ " \"tags\": [\n" + " 43,\n"
+ " 45\n" + " ],\n" + " \"parentId\": \"4\"\n" + "}",
function (p1, p2) {
console.log(p1)
console.log(p2)
}, function (p1, p2) {
console.log(p1)
console.log(p2)
})
} }
} }
} }

View File

@ -5,7 +5,8 @@ import QtQuick
QtObject { QtObject {
id: request id: request
property string baseUrl: "http://127.0.0.1:4523/m1/2914957-0-5604d062/" property string baseUrl: "http://127.0.0.1:4523/m1/2914957-0-default/"
//property string baseUrl: "http://192.168.156.74:8080/"
// GET // GET
function get(url, success, failure) { function get(url, success, failure) {
@ -20,17 +21,30 @@ QtObject {
// POST // POST
function post(url, arg, success, failure) { function post(url, arg, success, failure) {
var xhr = new XMLHttpRequest var xhr = new XMLHttpRequest
xhr.open("POST", baseUrl + url) xhr.open("POST", baseUrl + url, true)
xhr.setRequestHeader("Content-Length", arg.length) xhr.setRequestHeader('Content-Type', 'application/json')
xhr.setRequestHeader( xhr.withCredentials = true
"Content-Type",
"application/x-www-form-urlencoded;") //POST
xhr.onreadystatechange = function () { xhr.onreadystatechange = function () {
handleResponse(xhr, success, failure) handleResponse(xhr, success, failure)
} }
xhr.send(arg) xhr.send(arg)
} }
/* function post(url, arg, success, failure) {
var xhr = new XMLHttpRequest
xhr.open("POST", baseUrl + url)
xhr.setRequestHeader("Content-Length", arg.length)
xhr.setRequestHeader(
"Content-Type",
"application/x-www-form-urlencoded;") //POST
xhr.onreadystatechange = function () {
handleResponse(xhr, success, failure)
}
xhr.send(arg)
}*/
// //
function handleResponse(xhr, success, failure) { function handleResponse(xhr, success, failure) {
if (xhr.readyState === XMLHttpRequest.DONE) { if (xhr.readyState === XMLHttpRequest.DONE) {

View File

@ -128,6 +128,7 @@ FluArea {
right: layout_like.left right: layout_like.left
rightMargin: 20 rightMargin: 20
} }
onClicked: function () {}
} }
} }