Hello,
I have created bpm and bpm on Bonita studio. I am working on .net and able to query data from the database which is H2. The process uses form that is generated from the JSON contract form schema. I have problem posting data HTTP post using web API clients. On the client-side, all went fine and all statuses are Ok and data are serialized . I have created DTO for transfering data and when i insatiate process I go step by step debugging and everything is fine. Does Bonita community have a restriction with external API posting data?
Below you can see protion of the code what i have done so far and on console i have everuthing as it should be
[HttpPost("[action]")]
public async Task<IActionResult> Complexi([FromBody]RequestViewModel obj)
{
var id = (string)TempData["id"];
var url = await _bonitaClient.GetData();
using (var handler = new HttpClientHandler { UseCookies = false })
{
using (var client = new HttpClient(handler))
{
var formContent = new Dictionary<string, string>
{
{"username", "william.jobs"},
{"password", "bpm"},
{"redirect", "false"}
};
client.BaseAddress = new Uri(url);
client.DefaultRequestHeaders.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
string urls = "API/bpm/process/" + id + "/instantiation";
string urlt = "API/bpm/process/" + id + "/contract";
var setCookie = string.Empty;
var result = client.PostAsync("loginservice", new FormUrlEncodedContent(formContent)).Result;
var message = new HttpRequestMessage(HttpMethod.Get, urlt);
var st = "";
foreach (var header in result.Headers.Where(header => header.Key == "Set-Cookie"))
{
foreach (var value in header.Value)
{
st += value + ";";
}
break; // We only care about the first match.
}
message.Headers.Add("Cookie", st);
var Res = await client.SendAsync(message);
if (Res.IsSuccessStatusCode)
{
var json = JsonConvert.SerializeObject(obj);
var contacts = new StringContent(json, Encoding.UTF8, "application/json");
var t = await client.PostAsync(urls, contacts);
}
}
}
return Ok("Data has been sent");
}