很抱歉问了一个非常基本的问题,我是芭蕾舞女演员的新手,不知道如何进行。我复制粘贴了芭蕾舞女演员文档中“为计算器服务创建客户端”中的代码:
进口芭蕾舞女演员/http;进口芭蕾舞女演员/io;进口芭蕾舞女演员/原木;
端点 http:Client clientEndpoint { url: " http://localhost:9090 " };
功能主(字符串...参数){
http:Request req = new; // Set the JSON payload to the message to be sent to the endpoint. json jsonMsg = { a: 15.6, b: 18.9, operation: "add" }; req.setJsonPayload(jsonMsg); var response = clientEndpoint->post("/calculator/operation", request = req); match response { http:Response resp => { var msg = resp.getJsonPayload(); match msg { json jsonPayload => { string resultMessage = "Addition result " + jsonMsg["a"].toString() + " + " + jsonMsg["b"].toString() + " : " + jsonPayload["result"].toString(); io:println(resultMessage); } error err => { log:printError(err.message, err = err); } } } error err => { log:printError(err.message, err = err); } } }
然后当我在一个控制台中运行以下命令时
芭蕾舞女演员运行计算器
并在另一个控制台中运行以下命令
芭蕾舞女演员运行 client.bal
我收到以下错误消息:
错误:./client.bal:17:20:调用“post()”编译时没有足够的参数包含错误
下面显示的是示例服务代码
进口芭蕾舞女演员/http;
端点 http:Listener listener { port:9090 };
// 计算器 REST 服务 @http:ServiceConfig { basePath: "/calculator" } servicehttp:Service Calculator bind listener {
// Resource that handles the HTTP POST requests that are directed to // the path `/operation` to execute a given calculate operation // Sample requests for add operation in JSON format // `{ "a": 10, "b": 200, "operation": "add"}` // `{ "a": 10, "b": 20.0, "operation": "+"}` @http:ResourceConfig { methods: ["POST"], path: "/operation" } executeOperation(endpoint client, http:Request req) { json operationReq = check req.getJsonPayload(); string operation = operationReq.operation.toString(); any result = 0.0; // Pick first number for the calculate operation from the JSON request float a = 0; var input = operationReq.a; match input { int ivalue => a = ivalue; float fvalue => a = fvalue; json other => {} //error } // Pick second number for the calculate operation from the JSON request float b = 0; input = operationReq.b; match input { int ivalue => b = ivalue; float fvalue => b = fvalue; json other => {} //error } if(operation == "add" || operation == "+") { result = add(a, b); } // Create response message. json payload = { status: "Result of " + operation, result: 0.0 }; payload["result"] = check <float>result; http:Response response; response.setJsonPayload(payload); // Send response to the client. _ = client->respond(response); } }
谁能帮我理解我做错了什么。先感谢您!