Вы можете добавить базовую авторизацию в конфигурации конечной точки клиента.
endpoint soap:Client soapClient {
clientConfig: {
url: "http://localhost:9000",
auth: {
scheme: http:BASIC_AUTH,
username: "is_username",
password: "is_password"
}
}
};
Это добавит заголовок Authorization
в HTTP-запрос.Полный код будет выглядеть следующим образом:
import ballerina/http;
import ballerina/io;
import ballerina/log;
import wso2/soap;
endpoint soap:Client soapClient {
clientConfig: {
url: "http://localhost:9000",
auth: {
scheme: http:BASIC_AUTH,
username: "is_username",
password: "is_password"
}
}
};
public function main(string... args) {
xml body = xml `<tes:insert_employee_operation xmlns:tes="http://teste.cv">
<tes:name>{{username}}</tes:name>
<tes:age>10</tes:age>
<tes:ssn>25</tes:ssn>
</tes:insert_employee_operation>`;
soap:SoapRequest soapRequest = {
soapAction: "urn:insert_employee_operation",
payload: body
};
io:println(soapRequest);
var details = soapClient->sendReceive("/services/EmployeeService", soapRequest);
match details {
soap:SoapResponse soapResponse => {
io:println(soapResponse);
xml respostaXml = soapResponse.payload;
json respostaJson = respostaXml.toJSON({});
response.setJsonPayload(respostaJson);
_ = caller->respond(response);
}
soap:SoapError soapError => io:println(soapError);
}
}