Reputation: 823
I am doing scraping of page using PHP cURL
. I have to login to the website by passing credentials to login form action. Here is the cases I'm getting.:
Case #1:
When accessing page using browser, this is the form which is being submitted to the server.
<form id="formLogin" name="formLogin" method="post" action="../public/j_security_check">
<input type="hidden" id="j_token" name="j_token" value="0">
<input type="hidden" id="j_username" name="j_username" value="">
<input type="text" id="username_txt" name="username_txt" size="20" onChange="HidePageMessage()" onkeydown='onAutoSubmit(event)'>
<input type="password" id="j_password" name="j_password" size="20" onChange="HidePageMessage()" onkeydown='onAutoSubmit(event)' onkeypress="capsDetect(event)">
<select id="carrierCode" name="carrierCode" STYLE="width: 120px">
<option value="val1">Some Option</option>
<option value="val2">Some Option</option>
<option value="val3">Some Option</option>
<option value="valn">Some Option</option>
</select>
<input type="button" id="btnClose" value="Close" class="loginButton" onclick="window.close()" i18n_key="close">
<input type="button" id="btnLogin" value="Login" class="loginButton" onclick="login()" i18n_key="login">
<input type="hidden" id="hdnUserStatus" name="hdnUserStatus" value="" />
</form>
When I submit button with correct credentials, it sends data to the following url with these information:
General
Request URL:https://example.com/agents/public/j_security_check
Request Method:POST
Status Code:302 Moved Temporarily
Remote Address:86.96.201.171:443
Response Headers
Content-Length:0
Date:Wed, 08 Mar 2017 04:16:15 GMT
Location:http://example.com/agents/private/showXBEMain.action
Set-Cookie:aeroID=16395617314887938521488793852650522;expires=Tue, 02-Jan-2018 04:16:15 GMT;path=/;
Request Headers
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip, deflate, br
Accept-Language:en-GB,en-US;q=0.8,en;q=0.6
Cache-Control:max-age=0
Connection:keep-alive
Content-Length:136
Content-Type:application/x-www-form-urlencoded
Cookie:JSESSIONID=F16F95247A3E529FA526B5FBD6C9CE87.aapuga64; aeroID=16395617314887938521488793852650522
Host:domain.com
Origin:https://example.com
Referer:https://example.com/agents/private/showXBEMain.action
Upgrade-Insecure-Requests:1
User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36
Form Data
j_token:1
j_username: some_credential
username_txt: loginid
j_password: password
carrierCode: somecode
hdnUserStatus:
As a success result, it's redirected to another page which is correct, but when going to access this page using PHP cURL
, it's giving ' Invalid direct reference to form login page' and status code: 400
case #2:
When passing the same field with wrong credentials, it's giving status 200
and a message inside js code 'LOGINFAILED
' which is correct, and as expected.
case #3:
When passing the same failds with correct credentials, neither it's redirecting to another page as it should do, nor giving LOGINFAILED
message. it's giving 400
status code, and message as 'Invalid direct reference to form login page
'
I searched a lot about this on the web, it's a type of j_security_check
error of java
and the solutions for that is inside the code of server. And in my case I'm doing scraper where I do not know what they have written inside the server.
Upvotes: 0
Views: 271