Hi All,
How to call another Web API (the same box or other box) within Web API?, codes below does not work
[HttpPost]
[Route("/B2B/Core_RegistrationAsync")]
[AllowAnonymous]
public async Task<object> Core_RegistrationAsync([FromBody]JObject _jo)
{
try
{
string _company_name = (string)_jo["company_name"];
string _company_email = (string)_jo["company_email"];
string _core_client_id = (string)_jo["core_client_id"];
using (var client = new HttpClient())
{
var url = new Uri(_url);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Add("api_key", Models.AppSettings.Application.PTDigital.B2B_API_KEY);
client.DefaultRequestHeaders.Add("api_secret", Models.AppSettings.Application.PTDigital.B2B_API_SECRET);
var obj = new
{
client_id = _core_client_id,
company_name = _company_name,
company_email = _company_email
};
var json = JsonConvert.SerializeObject(obj);
var content = new StringContent(json, Encoding.UTF8, "application/json");
var response = await client.PostAsync(_url, content);
HttpStatusCode _statusCode = response.StatusCode;
if (_statusCode == HttpStatusCode.OK)
{
response.EnsureSuccessStatusCode();
string _res = response.Content.ReadAsStringAsync().Result;
if (response.IsSuccessStatusCode)
{
_ret = true;
}
}
}
How to call another Web API (the same box or other box) within Web API?, codes below does not work
[HttpPost]
[Route("/B2B/Core_RegistrationAsync")]
[AllowAnonymous]
public async Task<object> Core_RegistrationAsync([FromBody]JObject _jo)
{
try
{
string _company_name = (string)_jo["company_name"];
string _company_email = (string)_jo["company_email"];
string _core_client_id = (string)_jo["core_client_id"];
using (var client = new HttpClient())
{
var url = new Uri(_url);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Add("api_key", Models.AppSettings.Application.PTDigital.B2B_API_KEY);
client.DefaultRequestHeaders.Add("api_secret", Models.AppSettings.Application.PTDigital.B2B_API_SECRET);
var obj = new
{
client_id = _core_client_id,
company_name = _company_name,
company_email = _company_email
};
var json = JsonConvert.SerializeObject(obj);
var content = new StringContent(json, Encoding.UTF8, "application/json");
var response = await client.PostAsync(_url, content);
HttpStatusCode _statusCode = response.StatusCode;
if (_statusCode == HttpStatusCode.OK)
{
response.EnsureSuccessStatusCode();
string _res = response.Content.ReadAsStringAsync().Result;
if (response.IsSuccessStatusCode)
{
_ret = true;
}
}
}
Last edited: