how to get multiple data using url web api using 2 parameter contain search data
i have API URL like this :
https://services.marinetraffic.com/api/shipsearch/1d1675c236bae2931c5dbae2ea2e49fe6441d0c7/shipname:strilmoy/protocol:jsono
and response xml like this :
<VESSELS>
<vessel SHIPNAME="BUKIT SIGUNTANG" MMSI="525005017" IMO="9124536" SHIP_ID="703122" CALLSIGN="YFGS" TYPE_NAME="Passenger Ship" DWT="3686" FLAG="ID" COUNTRY="Indonesia" YEAR_BUILT="1996"MT_URL="http://www.marinetraffic.com/en/ais/details/ships/shipid:703122/mmsi:525005017/vessel:703122"/>
</VESSELS>
i want using search interface using input type and retrieve to table
with search parameter using shipname (BUKIT SIGUNTANG) or imo (9124536), on response API
[HttpGet]
public ActionResult Add(string IMO)
{
try
{
SetUpdateMessage("");
//Session["VesselSearchList"] = null;
if (string.IsNullOrEmpty(IMO))
{
return View();
}
List<VesselModel> vessel = new List<VesselModel>();
using (var client = new HttpClient())
{
string url = string.Format("{0}/{1}/imo:{2}/protocol:jsono", MTVesselSearch, Settings.Default.MarineTrafficApiKeyVesselSearch, IMO);
client.BaseAddress = new Uri(MTBaseUrl);
client.DefaultRequestHeaders.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage Res = client.GetAsync(url).Result;
if (Res.IsSuccessStatusCode)
{
string msgType = string.Empty;
ApiResponse apiResponse = new ApiResponse();
var EmpResponse = Res.Content.ReadAsStringAsync().Result;
try
{
var msgResponse = JsonConvert.DeserializeObject<MarineTrafficApiResponse>(EmpResponse);
if (msgResponse.errors != null)
{
msgType = "Error response from Marine Traffic API";
apiResponse = msgResponse.errors.FirstOrDefault();
}
else if (msgResponse.success != null)
{
apiResponse = msgResponse.success.FirstOrDefault();
msgType = "Success";
}
SetUpdateMessage(string.Format("{0}: Code {1}, {2}", msgType, apiResponse.code, apiResponse.detail));
}
catch { }
try
{
msgType = "Success";
var response = JsonConvert.DeserializeObject<List<VesselModel>>(EmpResponse);
Session["VesselSearchList"] = response;
ViewBag.result = response;
}
catch { }
}
else
{
SetUpdateMessage(string.Format("Error: {0} - {1}", (int)Res.StatusCode, Res.StatusCode));
}
}
}
catch (Exception ex)
{
SetUpdateMessage("Error: " + ex.Message);
}
ViewBag.SHIPNAME = IMO;
ViewBag.UpdateMessage = GetUpdateMessage();
return View();
}
<form method="GET" id="VesselSearch">
<span></span>
<input type="text" class="inputtext" placeholder="Type your ShipName here..." name="SHIPNAME" value="@ViewBag.SHIPNAME" style="height:25px;width:300px;text-align:left" />
<input type="submit" value="Search" class="Button" />
<input type="button" value="Back" class="Button" onclick="location.href='@Url.Action("Index", "Vessel")'" />
</form>