I am trying to make an HTTP Post request using any scripting language and want to Parse some content in returned response. An the content type is "application/x-www-form-urlencoded".
here is my sample code which i had written using bean shell.
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.entity.StringEntity;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.HttpClientBuilder;
int responseCode = Integer.parseInt(String.valueOf(prev.getResponseCode()));
if(responseCode=="200"){
Status="OK";
}else {
Status="Fail";
}
HttpClient httpClient = HttpClientBuilder.create().build();
try{
StringEntity data =new StringEntity("client_id=sample!&client_secret=abc1&response_type=token&grant_type=creden");
HttpPost request = new HttpPost("https://<<sample_Application URL>>");
request.addHeader("content-type", "application/x-www-form-urlencoded");
request.setEntity(data);
HttpResponse response = httpClient.execute(request);
log.info("response :" +response);
}catch(Exception e){
log.info("ExceptionKPI :" +e);
}
Thanks in advance. :)