Yes. The emulator does connect to the localhost using 10.0.2.2:888 as the
base uri. This is my basic connection routine. I just assumed i could
switch out my http://domain.appspot.com for the
http://10.0.2.2:8888/_ah/login url, but this doesnt seem to get me through
authentication. It does work for my domain.
private HttpResponse makeRequestNoRetry(String urlPath,
List<NameValuePair> params, boolean newToken, RequestMethod requestMethod)
throws Exception
{
// Get auth token for account
mAccountName =
PreferenceManager.getDefaultSharedPreferences(mContext).getString("accountName",
null);
Account account = new Account(mAccountName, "com.google");
String authToken = getAuthToken(mContext, account);
if (newToken) { // invalidate the cached token
AccountManager accountManager = AccountManager.get(mContext);
accountManager.invalidateAuthToken(account.type, authToken);
authToken = getAuthToken(mContext, account);
}
// Get ACSID cookie
DefaultHttpClient client = new DefaultHttpClient();
String continueURL = BASE_URL;
URI uri = new URI(AUTH_URL + "?continue=" +
URLEncoder.encode(continueURL, "UTF-8") +
"&auth=" + authToken);
HttpGet method = new HttpGet(uri);
final HttpParams getParams = new BasicHttpParams();
HttpClientParams.setRedirecting(getParams, false); // continue is not
used
method.setParams(getParams);
HttpResponse res = client.execute(method);
Header[] headers = res.getHeaders("Set-Cookie");
if (res.getStatusLine().getStatusCode() != 302 ||
headers.length == 0) {
return res;
}
String ascidCookie = null;
for (Header header: headers) {
if (header.getValue().indexOf("ACSID=") >=0) {
// let's parse it
String value = header.getValue();
String[] pairs = value.split(";");
ascidCookie = pairs[0];
}
}
uri = new URI(BASE_URL + urlPath);
HttpUriRequest request = null;
if (requestMethod == RequestMethod.GET)
{
// add parameters
String combinedParams = "";
if (params != null && !params.isEmpty())
{
combinedParams += "?";
for (NameValuePair p : params)
{
String paramString = p.getName() + "=" +
URLEncoder.encode(p.getValue(),"UTF-8");
if (combinedParams.length() > 1)
{
combinedParams += "&" + paramString;
}
else
{
combinedParams += paramString;
}
}
}
request = new HttpGet(uri + combinedParams);
}
else
{
// Make POST request
request = new HttpPost(uri);
if (params != null && !params.isEmpty())
{
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params,
"UTF-8");
((HttpPost) request).setEntity(entity);
}
}
request.setHeader("Cookie", ascidCookie);
request.setHeader("X-Same-Domain", "1"); // XSRF
res = client.execute(request);
return res;
}
--
You received this message because you are subscribed to the Google Groups
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine-java?hl=en.