project-mirai / mirai-api-http

Mirai HTTP API (console) plugin
GNU Affero General Public License v3.0
1.66k stars 343 forks source link

POST:{"code":400,"msg":"无效参数"} #630

Closed linux-rm closed 1 year ago

linux-rm commented 2 years ago

main.cpp:

#include <httplib.h>
#include <iostream>

#define CA_CERT_FILE "./ca-bundle.crt"

using namespace std;

int main()
{
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
        httplib::SSLClient cli("localhost", 8080);
        cli.set_ca_cert_path(CA_CERT_FILE);
        cli.enable_server_certificate_verification(true);
#else
        httplib::Client cli("localhost", 8080);
#endif
        auto res = cli.Get("/");
        while (1)
        {
                cout << "\apost/get/exit:";
                string opinion;
                cin >> opinion;
                if(opinion == "exit")
                {
                        exit(0);
                }
                cout << "\acmd:";
                string cmd;
                cin >> cmd;
                if(opinion == "get")
                {
                        res = cli.Get(cmd);
                }
                if(opinion == "post")
                {
                        cout << "\atext:";
                        string text;
                        cin >> text;
                        res = cli.Post(cmd, text, "application/x-www-form-urlencoded");
                        // res = cli.Post(cmd,"verifyKey=1234567890", "text/plain");
                        /*
                        httplib::Params params{
                                { "verifyKey", "1234567890"}
                         };
                        res = cli.Post(cmd, params);
                        */
                }

                if(res)
                {
                        cout << res->status << endl;
                        cout << res->get_header_value("Content-Type") << endl;
                        cout << res->body << endl;
                }
                else
                {
                        cout << "error code: " << res.error() << std::endl;
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
                        auto result = cli.get_openssl_verify_result();
                        if (result)
                        {
                                cout << "verify error: " << X  509_ verify_cert_error_string(result) << endl;
                        }
#endif
                }
                cout << "\n================" << endl;
        }
        return 1;
}

试过以下办法结果都相同:

// 其中cmd都输入/verify

res = cli.Post(cmd,"verifyKey=1234567890", "text/plain");

httplib::Params params{
{"verifyKey", "1234567890"}
};
res = cli.Post(cmd, params);

运行结果: 截图

mcl/logs/latest.log部分:

2022-10-02 06:44:50 E/Mah Debug: kotlinx.serialization.json.internal.JsonDecodingException: Expected start of the object '{', but had 'EOF' instead
JSON input: verifyKey=1234567890                                              kotlinx.serialization.json.internal.JsonDecodingException: Expected start of the object '{', but had 'EOF' instead                                          JSON input: verifyKey=1234567890                                                      at kotlinx.serialization.json.internal.JsonExceptionsKt.JsonDecodingException(JsonExceptions.kt:24)                                                         at kotlinx.serialization.json.internal.JsonExceptionsKt.JsonDecodingException(JsonExceptions.kt:32)                                                         at kotlinx.serialization.json.internal.AbstractJsonLexer.fail(AbstractJsonLexer.kt:524)                                                                     at kotlinx.serialization.json.internal.AbstractJsonLexer.fail$kotlinx_serialization_json(AbstractJsonLexer.kt:221)                                          at kotlinx.serialization.json.internal.AbstractJsonLexer.unexpectedToken(AbstractJsonLexer.kt:204)                                                          at kotlinx.serialization.json.internal.StringJsonLexer.consumeNextToken(StringJsonLexer.kt:74)                                                              at kotlinx.serialization.json.internal.StreamingJsonDecoder.beginStructure(StreamingJsonDecoder.kt:41)                                                      at mirai-api-http-2.6.2.jar//net.mamoe.mirai.api.http.adapter.internal.dto.VerifyDTO$$serializer.deserialize(auth.kt:17)                                    at mirai-api-http-2.6.2.jar//net.mamoe.mirai.api.http.adapter.internal.dto.VerifyDTO$$serializer.deserialize(auth.kt:17)                                    at kotlinx.serialization.json.internal.PolymorphicKt.decodeSerializableValuePolymorphic(Polymorphic.kt:59)                                                  at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue(StreamingJsonDecoder.kt:36)                                             at kotlinx.serialization.json.Json.decodeFromString(Json.kt:100)              at mirai-api-http-2.6.2.jar//net.mamoe.mirai.api.http.adapter.internal.serializer.BuiltinJsonSerializer.decode(BuiltinJson.kt:76)
        at mirai-api-http-2.6.2.jar//net.mamoe.mirai.api.http.adapter.http.router.VerifyKt$authRouter$1$invoke$$inlined$httpVerify$1$1.invokeSuspend(dsl.kt:200)
        at mirai-api-http-2.6.2.jar//net.mamoe.mirai.api.http.adapter.http.router.VerifyKt$authRouter$1$invoke$$inlined$httpVerify$1$1.invoke(dsl.kt)
        at mirai-api-http-2.6.2.jar//net.mamoe.mirai.api.http.adapter.http.router.VerifyKt$authRouter$1$invoke$$inlined$httpVerify$1$1.invoke(dsl.kt)
        at mirai-api-http-2.6.2.jar[shared]//io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:248)
        at mirai-api-http-2.6.2.jar[shared]//io.ktor.util.pipeline.SuspendFunctionGun.proceed(SuspendFunctionGun.kt:116)
        at mirai-api-http-2.6.2.jar[shared]//io.ktor.util.pipeline.SuspendFunctionGun.execute(SuspendFunctionGun.kt:136)
        at mirai-api-http-2.6.2.jar[shared]//io.ktor.util.pipeline.Pipeline.execute(Pipeline.kt:78)
        at mirai-api-http-2.6.2.jar[shared]//io.ktor.routing.Routing.executeResult(Routing.kt:155)
        at mirai-api-http-2.6.2.jar[shared]//io.ktor.routing.Routing.interceptor(Routing.kt:39)
        at mirai-api-http-2.6.2.jar[shared]//io.ktor.routing.Routing$Feature$install$1.invokeSuspend(Routing.kt:107)
        at mirai-api-http-2.6.2.jar[shared]//io.ktor.routing.Routing$Feature$install$1.invoke(Routing.kt)
        at mirai-api-http-2.6.2.jar[shared]//io.ktor.routing.Routing$Feature$install$1.invoke(Routing.kt)
        at mirai-api-http-2.6.2.jar[shared]//io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:248)
        at mirai-api-http-2.6.2.jar[shared]//io.ktor.util.pipeline.SuspendFunctionGun.proceed(SuspendFunctionGun.kt:116)
        at mirai-api-http-2.6.2.jar//net.mamoe.mirai.api.http.adapter.http.feature.auth.Authorization$install$1.invokeSuspend(Authorization.kt:41)
        at mirai-api-http-2.6.2.jar//net.mamoe.mirai.api.http.adapter.http.feature.auth.Authorization$install$1.invoke(Authorization.kt)
        at mirai-api-http-2.6.2.jar//net.mamoe.mirai.api.http.adapter.http.feature.auth.Authorization$install$1.invoke(Authorization.kt)
        at mirai-api-http-2.6.2.jar[shared]//io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:248)
        at mirai-api-http-2.6.2.jar[shared]//io.ktor.util.pipeline.SuspendFunctionGun.proceed(SuspendFunctionGun.kt:116)
        at mirai-api-http-2.6.2.jar//net.mamoe.mirai.api.http.adapter.http.feature.handler.HttpRouterAccessHandler.intercept(HttpRouterAccessHandler.kt:36)
        at mirai-api-http-2.6.2.jar//net.mamoe.mirai.api.http.adapter.http.feature.handler.HttpRouterAccessHandler.access$intercept(HttpRouterAccessHandler.kt:25)
        at mirai-api-http-2.6.2.jar//net.mamoe.mirai.api.http.adapter.http.feature.handler.HttpRouterAccessHandler$Feature$install$1.invokeSuspend(HttpRouterAccessHandler.kt:91)
        at mirai-api-http-2.6.2.jar//net.mamoe.mirai.api.http.adapter.http.feature.handler.HttpRouterAccessHandler$Feature$install$1.invoke(HttpRouterAccessHandler.kt)
        at mirai-api-http-2.6.2.jar//net.mamoe.mirai.api.http.adapter.http.feature.handler.HttpRouterAccessHandler$Feature$install$1.invoke(HttpRouterAccessHandler.kt)
        at mirai-api-http-2.6.2.jar[shared]//io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:248)
        at mirai-api-http-2.6.2.jar[shared]//io.ktor.util.pipeline.SuspendFunctionGun.proceed(SuspendFunctionGun.kt:116)
        at mirai-api-http-2.6.2.jar[shared]//io.ktor.util.pipeline.SuspendFunctionGun.execute(SuspendFunctionGun.kt:136)
        at mirai-api-http-2.6.2.jar[shared]//io.ktor.util.pipeline.Pipeline.execute(Pipeline.kt:78)
        at mirai-api-http-2.6.2.jar[shared]//io.ktor.server.engine.DefaultEnginePipelineKt$defaultEnginePipeline$2.invokeSuspend(DefaultEnginePipeline.kt:127)
        at mirai-api-http-2.6.2.jar[shared]//io.ktor.server.engine.DefaultEnginePipelineKt$defaultEnginePipeline$2.invoke(DefaultEnginePipeline.kt)
        at mirai-api-http-2.6.2.jar[shared]//io.ktor.server.engine.DefaultEnginePipelineKt$defaultEnginePipeline$2.invoke(DefaultEnginePipeline.kt)
        at mirai-api-http-2.6.2.jar[shared]//io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:248)
        at mirai-api-http-2.6.2.jar[shared]//io.ktor.util.pipeline.SuspendFunctionGun.proceed(SuspendFunctionGun.kt:116)
        at mirai-api-http-2.6.2.jar[shared]//io.ktor.util.pipeline.SuspendFunctionGun.execute(SuspendFunctionGun.kt:136)
        at mirai-api-http-2.6.2.jar[shared]//io.ktor.util.pipeline.Pipeline.execute(Pipeline.kt:78)
        at mirai-api-http-2.6.2.jar[shared]//io.ktor.server.cio.CIOApplicationEngine$handleRequest$2.invokeSuspend(CIOApplicationEngine.kt:196)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
        at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:749)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
        at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
ryoii commented 2 years ago

把 debug 模式打开,看一些接受到的参数到底是什么

linux-rm commented 2 years ago

把 debug 模式打开,看一些接受到的参数到底是什么

怎么打开

ryoii commented 2 years ago

参考配置文件

cssxsh commented 1 year ago

你传入的格式有误 应该是

{ "verifyKey": 1234567890 }
linux-rm commented 1 year ago

已解决

umena337 commented 1 year ago

{"verifyKey": "INITKEYqkqm3CKb"}