Hi
I have below code & i want if successfully done then Sucess message should get displayed else if there ie error or Awb no does not exists then it should show some message
var client = new RestClient("api.nimbuspost.com/v1/shipments/cancel");
client.Timeout = -1;
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
var body = @"{" + "\n" +
@" ""email"" : ""[email protected]""," + "\n" +
@" ""password"" : ""T!""" + "\n" +
@"awb : " + awb + " \n" +
@"}";
request.AddHeader("Authorization", "Bearer " + token);
request.AddParameter("application/json", body, ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
Thanks
Ramco RamcoPosted Dec 26, 2022, 11:17 AM
Hi Vishal
I have checked now in var data = response.Content; it is showing data = ""
Thanks
Vishal JoshiPosted Dec 26, 2022, 11:10 AM
The HTTP 200 OK success status response code indicates that the request has succeeded.
So it's the same as 200. you can check if (response.status == "OK")
Ramco RamcoPosted Dec 26, 2022, 10:50 AM
Hi Vishal
It is showing response.status = OK
response.description ="Ok"
Thanks
Vishal JoshiPosted Dec 26, 2022, 10:27 AM
Hello Romco
Can you please check response.Status. please check the value if it's number then set if condition like below
Ramco RamcoPosted Dec 26, 2022, 10:10 AM
Hi Vishal
It is still giving error on Status = true, / Status = false,
Thanks
Vishal JoshiPosted Dec 26, 2022, 10:07 AM
Hello
You need to change if condition.
Existing
Change it with
Conclusion, response.status is number type and it will return HTTP response number code.
Thanks
Ramco RamcoPosted Dec 26, 2022, 9:57 AM
Hi
It is giving error - cannot implicitly convert type boolean to int on Status = true/False
Thanks
Amit MohantyPosted Dec 26, 2022, 9:40 AM
Hey, if your API returns Status as true or false then try the below code.
Vishal JoshiPosted Dec 26, 2022, 9:38 AM
Hello
You can use the response to check response is valid or not and as per requirement, you can display the message.
Try the below code to test the response.
Thanks
Ramco RamcoPosted Dec 26, 2022, 8:43 AM
Hi Jomis
I am using .net c# not MVC. How this code will work in .net c#
On this line JsonResult result = new JsonResult(); it is saying to install Microsoft.Asp.NetVore.MVC.Formatters.Json.
Thanks
Jomis PjPosted Dec 26, 2022, 8:25 AM
//Just defined above your code.
JsonResult result = new JsonResult();
ResultModel rm = new ResultModel();
Ramco RamcoPosted Dec 26, 2022, 8:17 AM
Hi
Where u have defined rm & result.
Thanks
Jomis PjPosted Dec 26, 2022, 8:05 AM
New Code:
Create Model to return a data in your code.
Jomis PjPosted Dec 26, 2022, 8:02 AM
public class InstallmentResultModel Data { get; set; }
{
public string Message { get; set; }
public int Status { get; set; }
public List
}
Ramco RamcoPosted Dec 26, 2022, 7:57 AM
Hi
What is vInstallmentResultModel. What should be the datatype of result.
Thanks
Jomis PjPosted Dec 26, 2022, 7:37 AM
Please check full code.