0

我已经实现了一个 Ballerina(ballerina 0.91) 服务来调用在 localhost 上运行的 https REST 服务。我使用 http:ClientConnector 来调用该服务。这是我的示例代码。

http:ClientConnector clientConnector = create http:ClientConnector("https://localhost:9445/");
string token = "admin:admin";
string auth = utils:base64encode(token);
message request = {};
messages:setHeader(request,"Basic ",auth);
message response = clientConnector.get("bpmn/runtime/process-instances/",request);

顺便说一下,我与 WSO2 EI 中的业务流程进行交互。

问题是当我正常调用此服务时,它没有响应或给出如下错误。

error: ballerina.lang.errors:Error, message: failed to invoke 'get' action in ClientConnector. response was not received within sender timeout of 180 seconds
    at ballerina.net.http:ClientConnector.get(<native>:0)
    at org.wso2.ballerina.connectors.basicauth:ClientConnector.get(org/wso2/ballerina/connectors/basicauth/ClientConnector.bal:28)
    at .:main(MainFile.bal:21)
4

2 回答 2

3

这是 0.95.0 的工作示例。我正在使用邮递员基本身份验证端点:

import ballerina.net.http;
function main(string[] args) {
   endpoint<http:HttpClient> httpConnector{
       create http:HttpClient("https://postman-echo.com",{});
   }
http:Request req = {};
http:Response resp = {};
req.addHeader("Authorization", "Basic cG9zdG1hbjpwYXNzd29yZA==");
resp,_ = httpConnector.get("/basic-auth",req);
println("Auth request:");
println(resp.getJsonPayload());
}
于 2017-11-14T05:23:11.707 回答
2

我通过将 WSO2-EI 的证书添加到 Ballerina client-truststore.jks 文件来解决我的问题。

于 2017-11-14T05:25:05.230 回答