更新当前用户信息

🔐 需要登录(User权限)

PUT/api/user/self

更新当前用户信息

🔐 需要登录(User权限)

请求体

Content-Type: application/json

字段类型必填说明
usernamestring
display_namestring
passwordstring
original_passwordstring

示例代码

curl -X PUT "https://api.nodeprice.com/api/user/self" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <token>" \
  -d '{
  "username": "string",
  "display_name": "string",
  "password": "string",
  "original_password": "string"
}'
const url = "https://api.nodeprice.com/api/user/self";
const body = {
  "username": "string",
  "display_name": "string",
  "password": "string",
  "original_password": "string"
};

const response = await fetch(url, {
  method: "PUT",
  headers: {
    "Content-Type": "application/json",
    "Authorization": "Bearer <token>"
  },
  body: JSON.stringify(body)
});

console.log(await response.text());
package main

import (
	"fmt"
	"io"
	"net/http"
	"strings"
)

func main() {
	url := "https://api.nodeprice.com/api/user/self"
	body := strings.NewReader(`{
  "username": "string",
  "display_name": "string",
  "password": "string",
  "original_password": "string"
}`)
	req, err := http.NewRequest("PUT", url, body)
	if err != nil {
		panic(err)
	}
	req.Header.Set("Content-Type", "application/json")
	req.Header.Set("Authorization", "Bearer <token>")
	resp, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()
	data, err := io.ReadAll(resp.Body)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(data))
}
import requests

url = "https://api.nodeprice.com/api/user/self"

body = """{
  "username": "string",
  "display_name": "string",
  "password": "string",
  "original_password": "string"
}"""

response = requests.request("PUT", url, data=body, headers={
  "Content-Type": "application/json",
  "Authorization": "Bearer <token>"
})

print(response.text)
OkHttpClient client = new OkHttpClient();

MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\n"
    + "  \"username\": \"string\",\n"
    + "  \"display_name\": \"string\",\n"
    + "  \"password\": \"string\",\n"
    + "  \"original_password\": \"string\"\n"
    + "}");
Request request = new Request.Builder()
    .url("https://api.nodeprice.com/api/user/self")
    .method("PUT", body)
    .addHeader("Content-Type", "application/json")
    .addHeader("Authorization", "Bearer <token>")
    .build();

Response response = client.newCall(request).execute();
System.out.println(response.body().string());
#include <stdio.h>
#include <curl/curl.h>

int main(void) {
    CURL *curl = curl_easy_init();
    if (curl == NULL) {
        return 1;
    }

    struct curl_slist *headers = NULL;
    headers = curl_slist_append(headers, "Content-Type: application/json");
    headers = curl_slist_append(headers, "Authorization: Bearer <token>");

    curl_easy_setopt(curl, CURLOPT_URL, "https://api.nodeprice.com/api/user/self");
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "{\n"
        + "  \"username\": \"string\",\n"
        + "  \"display_name\": \"string\",\n"
        + "  \"password\": \"string\",\n"
        + "  \"original_password\": \"string\"\n"
        + "}");
    curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);

    CURLcode code = curl_easy_perform(curl);
    if (code != CURLE_OK) {
        fprintf(stderr, "%s\n", curl_easy_strerror(code));
    }

    curl_slist_free_all(headers);
    curl_easy_cleanup(curl);
    return 0;
}
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static async Task Main()
    {
        var client = new HttpClient();
        var request = new HttpRequestMessage(HttpMethod.Put, "https://api.nodeprice.com/api/user/self");
        request.Headers.Add("Authorization", "Bearer <token>");
        request.Content = new StringContent("{\n"
            + "  \"username\": \"string\",\n"
            + "  \"display_name\": \"string\",\n"
            + "  \"password\": \"string\",\n"
            + "  \"original_password\": \"string\"\n"
            + "}", Encoding.UTF8, "application/json");

        var response = await client.SendAsync(request);
        Console.WriteLine(await response.Content.ReadAsStringAsync());
    }
}

响应

200 成功