3

我在芭蕾舞女演员作曲家中运行我的服务,然后我使用Windows cmd来调用服务,curlcmd抱怨这curl不是一个可识别的命令。

我怎么能做到呢cmd

请帮忙。

4

2 回答 2

2
  1. 创建您的服务文件,这里是hello_service.bal.

import ballerina/http;

endpoint http:Listener listener {
    port:9090
};

service<http:Service> hello bind listener {
    sayHello (endpoint caller, http:Request request) {

        http:Response response = new;

        response.setTextPayload("Hello World!\n");

        _ = caller -> respond(response);
    }
}


2.在cmd上运行。ballerina run hello_service.bal
3. 制作一个新main.bal文件。


import ballerina/http;
import ballerina/log;
import ballerina/io;

endpoint http:Client clientEndpoint {
    url: "http://localhost:9090"
};

function main(string... args) {
    // Send a GET request to the Hello World service endpoint.
    var response = clientEndpoint->get("/hello/sayHello");

    match response {
        http:Response resp => {
            io:println(resp.getTextPayload());
        }
        error err => {
            log:printError(err.message, err = err);
        }
    }
}


4. ballerina run main.bal.
Hello World!5. 你现在可以在cmd上 看到结果了。


于 2018-08-11T18:02:29.800 回答
1

您无需使用 cURL 来调用 Ballerina HTTP 服务。您可以使用通常使用的 HTTP 客户端(例如Postman)。如果你真的想要,你也可以在 Windows 中安装 cURL:https ://curl.haxx.se/download.html 。

于 2018-08-10T09:16:47.827 回答