Table of Contents [Hide/Show]
EnvironmentCredentialsRequest FormatResponse FormatSample Code Calling a RESTful Web Service C# Java
public string PostXml(string apiUrl, string token, string xmlRequest) { using (var client = new HttpClient()) { client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml")); client.DefaultRequestHeaders.Authorization = AuthenticationHeaderValue.Parse("Bearer " + token); var content = new StringContent(xmlRequest, Encoding.UTF8, "application/xml"); var responseMsg = client.PostAsync(new Uri(apiUrl), content).Result; var response = responseMsg.Content.ReadAsStringAsync().Result; return response; } }
var searchResult = PostXml("https://gateway-uat.iso.com/underwriting/aplusauto/claims/v1.0", "7ca327234c09w8b99b9bda03c171a5c", xmlRequest);
public String postCallToApiService(String endPoinUrl, String accessToken, String requestXML) { String responseStr = ""; HttpPost postMethod = new HttpPost(endPointUrl); postMethod.setHeader("Content-Type", "application/xml"); postMethod.setHeader("Accept", "application/xml"); postMethod.setHeader("Authorization", "Bearer "+accessToken); DefaultHttpClient httpClient = new DefaultHttpClient(); InputStream responseStream = null; try { postMethod.setEntity(new StringEntity(requestXML)); HttpResponse response = httpClient.execute(postMethod); responseStream = response.getEntity().getContent(); responseStr = IOUtils.toString(responseStream); } catch (UnsupportedEncodingException e) { //log and handle exception } catch (ClientProtocolException e) { // log and handle exception }catch (SocketTimeoutException e) { // log and handle exception }catch (ConnectTimeoutException e) { // log and handle exception } catch (IOException e) { // log and handle exception } finally { // release the connection try { if(responseStream!=null){ responseStream.close(); } if(httpClient!=null){ httpClient.getConnectionManager().shutdown(); } } catch (IOException e) { // log and handle exception } } return responseStr; }
String searchResult = postCallToApiService("https://gateway-uat.iso.com/underwriting/aplusauto/claims/v1.0", "7ca327234c09w8b99b9bda03c171a5c", xmlRequest);