I am working on an app, where I have to parse the third party website after login in to it. Where https://customer.onlinelic.in/LICEPS/appmanager/Agent/AgentHome
is home page after login. From here there are some links in the response page where I parse and make a request to each of those links.One of the links take me to a page where I have to enter some inputs and submit the form and it returns me some data based on inputs.
If I do this in web the result is coming fine. But if I request same URL from Android using HttpUrlConnection
the response coming completely different, infact it is returning above mentioned page, which is home page.
If I do the request in android with same request parameters, and valid session id and valid input parameters, response coming differently. Response code is proper but response content is wrong.
I checked all headers and parameters, but of no use. Can any one tell me what might be the reason to get different responses.
EDIT Here is my code for request
public String initiateRequest(String url, String payload, String referer, String requestType)
{
String response = null;
try
{
URL urls = new URL(url);
HttpsURLConnection urlconn = (HttpsURLConnection) urls.openConnection();
urlconn.setDoInput(true);
urlconn.setDoOutput(true);
urlconn.setRequestMethod(requestType);
urlconn.setConnectTimeout(30000);
urlconn.setReadTimeout(30000);
urlconn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
if (!referer.equalsIgnoreCase("")){
urlconn.setRequestProperty("referer", "https://customer.onlinelic.in/LICEPS/appmanager/Agent/AgentHome?_nfpb=true&_windowLabel=Agent_policy_tracker_portlet&Agent_policy_tracker_portlet_actionOverride=%2Fportlets%2Fagent%2FAgentPolicyTracker%2Fbegin");
urlconn.setRequestProperty("User-Agent","Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36");
urlconn.setRequestProperty("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
// urlconn.setRequestProperty("Accept-Encoding","gzip, deflate, br");
urlconn.setRequestProperty("Accept-Language","en-GB,en;q=0.8,en-US;q=0.6,fr;q=0.4");
urlconn.setRequestProperty("Cache-Control","max-age=0");
}
OutputStream os = urlconn.getOutputStream();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os));
writer.write(payload);
writer.close();
os.close();
response = ServiceNetworkCommunicator.readDataFromInputStream(urlconn.getInputStream());
} catch (Exception e) {
e.printStackTrace();
}
return response;
}
Session is managed by CookieHandler