Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Fitret
Mar 25, 2003

We are rolling for the King of All Cosmos!
I posted this in the Android thread, but that thread is sort of dead and this isn't really related to Android development, but general Java development. Anyway...


I'm trying to make a Wizards of the Coast's DDI Compenium viewer app for Android and I'm running into problems with authentication. Wizards of course has no documentation for their authentication method, and looking at all the threads on this issue, it appears that no one has really figured it out, or at least bothered to figure it out and post about it. However, I know there's an iPhone app that lets you browse the compendium, and it logs in for you, so it must be possible.

Their login page has a fairly basic HTML form:
code:
<form name="form1" method="post" action="login.aspx" id="form1"> 
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKLTMxMzExNzE1NGRkPb/13oDMUJchqfP74F0S6Ir26k4=" /> 
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWBAK744fKAgKyzcaDDQLyveCRDwK4+vrXBeDExHjW9/520ziutTg1ie5Br1aJ" /> 
<input name="email" type="text" id="email" /> 
<input name="password" type="password" id="password" /> 
<input type="submit" name="InsiderSignin" value="Sign In" id="InsiderSignin" /> 
</form>
There are some session related variables, so first I parse the site to get those (that works fine). From there, it seemed like the easiest solution was to use an HttpResponse object to make a POST call on login.aspx. Then, I attempt to get the authenticated web page.
However, it's not working:

code:
public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.entry_view);
	    
	    Intent i = getIntent();

	    webView_entry = (WebView) findViewById(R.id.webView_entry);
	    webView_entry.getSettings().setJavaScriptEnabled(true);
	    
	    try {
	    	URL myURL = new URL("http://www.wizards.com/dndinsider/compendium/login.aspx"); 
	    	URLConnection ucon;
			ucon = myURL.openConnection();
			lex = new Lexer(ucon);
			Node n = lex.nextNode();
			String viewState = null, eventValidation = null;
			while (n != null && (viewState == null || eventValidation == null)) {
				String tag = n.toHtml();
				
				if (tag.contains("__VIEWSTATE")) {	
					tag = tag.substring(tag.indexOf("value=") + 7);
					tag = tag.substring(0, tag.indexOf("\""));
					viewState = tag;
				}
				
				if (tag.contains("__EVENTVALIDATION")) {	
					tag = tag.substring(tag.indexOf("value=") + 7);
					tag = tag.substring(0, tag.indexOf("\""));
					eventValidation = tag;
				}
				
				n = lex.nextNode();
			}
			
			if ( viewState != null && eventValidation != null ) {
				BasicResponseHandler brh = new BasicResponseHandler();
			    DefaultHttpClient client = new DefaultHttpClient();
			    HashMap<String,String> hm = new HashMap<String,String>();
				
			    hm.put("email", username);
			    hm.put("password", password);
			    hm.put("__EVENTVALIDATION", eventValidation);
			    hm.put("__VIEWSTATE",viewState);
			    hm.put("InsiderSignin","Sign In");
				
			    HttpResponse response = doPost("http://www.wizards.com/dndinsider/compendium/login.aspx",hm,client);
			    try {
					brh.handleResponse(response);
				} catch (Exception e) {
					Log.e(TAG, e.getMessage());
				}
			    
			    if ( response != null ) {
			    	webView_entry.loadUrl(i.getStringExtra("com.package.compendiumviewer.Url"));
			    } else {
			    	showDialog(BAD_PASS);
			    }
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 	    
	}
    
    public static HttpResponse doPost(String mUrl, HashMap<String, String> hm, DefaultHttpClient httpClient) {
		HttpResponse response = null;
	
		HttpPost postMethod = new HttpPost(mUrl);
	
		if (hm == null) return null;
	
		try {
			List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
			Iterator<String> it = hm.keySet().iterator();
			String k, v;
	
			while (it.hasNext()) {
				k = it.next();
				v = hm.get(k);
				nameValuePairs.add(new BasicNameValuePair(k, v));
			}
	
			postMethod.setEntity(new UrlEncodedFormEntity(nameValuePairs));
			response = httpClient.execute(postMethod);
			Log.i(TAG, "STATUS CODE: " + String.valueOf(response.getStatusLine().getStatusCode()));
		} catch (Exception e) {
			Log.e(TAG, e.getMessage());
		}
	
		return response;
	}
Any thoughts? The HTTP Post response returns a 200, so I have no clue how to even begin debugging this.

Adbot
ADBOT LOVES YOU

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply