<form id="login" action="https://www.deviantart.com/users/login" method="post">
<input type="hidden" name="ref" value="https://www.deviantart.com/users/loggedin" />
<table align="center" cellpadding="10">
<tr>
<td style="text-align:right">
<label>
<strong>Deviant Name</strong>
<input class="text" type="text" name="username" autofocus="autofocus"/>
</label>
</td>
</tr>
<tr>
<td style="text-align:right">
<label>
<strong>Password</strong>
<input class="text" type="password" name="password"/>
</label>
</td>
</tr>
<tr>
<td align="center"><input class="button" type="submit" value="Log In"/></td>
</tr>
<tr>
<td>
<label for="reusetoken"><input type="checkbox" class="checkbox" id="reusetoken" name="reusetoken" value="1" checked="checked" style="vertical-align: middle"/> Don't log me out of other browsers</label>
</td>
</tr>
</table>
</form>
</div>
I am new to using httpurlconnection, but this is what I currently have and it doesn't work. (It's supposed to redirect to either a correct login page or an incorrect one.)
HttpURLConnection conn = (HttpURLConnection) new URL("https://www.deviantart.com/users/login").openConnection();
HttpURLConnection.setFollowRedirects(true);
String agent = "Mozilla/4.0";
String rawData = "ref=https://www.deviantart.com/users/loggedin&username=" + username + "&password=" + password + "&reusetoken=1";
String type = "application/x-www-form-urlencoded";
String encodedData = URLEncoder.encode(rawData);
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty( "User-Agent", agent );
conn.setRequestProperty( "Content-Type", type );
conn.setRequestProperty( "Content-Length",
String.valueOf(encodedData.length()) );
OutputStream os = conn.getOutputStream();
os.write( encodedData.getBytes() );
os.flush();
int rc = conn.getResponseCode();
if (rc == HttpURLConnection.HTTP_OK) {
System.out.println(conn.getURL().toExternalForm());
}
Thanks!

New Topic/Question
Reply




MultiQuote










|