Re: [android-developers] Re: c2DM error when third-party server sends data to push
Hi Jose, No luck for me I guess. I remove the '\n' from the Auth= value and followed the advice you had given but I got the following response: Jan 9, 2011 6:18:47 PM org.apache.http.impl.client.DefaultRequestDirector handleResponse WARNING: Authentication error: Unable to respond to any of these challenges: {} HTTP/1.1 401 Unauthorized Content-Type: text/html; charset=UTF-8 Date: Mon, 10 Jan 2011 00:18:57 GMT Expires: Mon, 10 Jan 2011 00:18:57 GMT Cache-Control: private, max-age=0 X-Content-Type-Options: nosniff X-Frame-Options: SAMEORIGIN X-XSS-Protection: 1; mode=block Server: GSE Transfer-Encoding: chunked HTML HEAD TITLEUnauthorized/TITLE /HEAD BODY BGCOLOR=#FF TEXT=#00 H1Unauthorized/H1 H2Error 401/H2 /BODY /HTML Not sure how to get this thing working. Nagaraj On Sun, Jan 9, 2011 at 12:27 AM, Nagaraj Ramarao nraj.tes...@gmail.comwrote: Hi Jose, Happy New Year 2011! No I haven't got back to testing this yet. I am busy with some other related issue. Hopefully I will be able to fix it soon before I can fix and test this issue. Thanks for your suggestions. I will try them as soon as I get a chance. I will keep you posted. Regards, Nagaraj On Mon, Jan 3, 2011 at 9:44 AM, Jose Ignacio Gil Jaldo naranj...@gmail.com wrote: Hi Nagaraj, I made it work... The point is: what are you sending as Auth token? the whole response that you got from /ClientLogin? or just the Auth= section? (Without the Auth=). You have to send the second one. If you're already doing it that way, try removing all \n in that String. You will also have to disable expect:continue in http requests (it's something that sends only the headers and if it's ok, continues sending the body). To do so: HttpParams params = new BasicHttpParams(); HttpProtocolParams.setUseExpectContinue(params, false); HttpClient httpclient = new DefaultHttpClient(params); That way it worked for me... On Jan 3, 11:25 am, Jose Ignacio Gil Jaldo naranj...@gmail.com wrote: Hi Nagaraj, could you make it work? I also tried downloading sources from google examples (JumpNote and Google2Chrome) and I couldn't make them work due to Authentication error (I think it could be related to something that Nasif Nooruden pointed you out about trimming the Auth string). However in my code, I've tried trimming the string and then I get 401 - UnAuthorized (I suppose it is because I have wrongly changed the auth string). Could it be an Apache HTTP related issue? But for me the most strange thing is that I can see the header in my POST request and the value of Content-Length is the same as the length of the POST parameters (and I have no querystring parameters). On Dec 27 2010, 6:18 pm, Jose Ignacio Gil Jaldo naranj...@gmail.com wrote: I am having the same problem as you and I think it's not my mistake I have checked the tcpdump (to do it I changed from https to http to have plain text). POST /c2dm/send HTTP/1.1 Authorization: GoogleLogin auth=SID=DQAAALw7O-9sDrg_FXztPEQ7fcfqBmPtCtIcN3gX4wTsXf7AmfQh5eetqv5jQm6FGt7QvjMJNaoZFlLNG- pTSPl07dQWCwM2tNSnbFCS6FO- Xe0Q0SJ6Ok4gipqqArAB2uh7mvgtHRguiWaP38IRVHcQjG4fhpo0K6LIZN0fBoE__FXl5ukqsIVc8Qo_ezXOspC_MZew76G6AvfkqwyMTM7XWzrgHDT9D9MlbgnuAWpR_XOA1KKOVO- eHFXp1UsCE6FM6mQ LSID=DQAAAL8AAADFjsO1Q_TnSqwZgm3HYxQsb08JcQxFwC_oucPZ3eEiqFNLhuQWJI_ZVS- iMuZKphHsmghU7I1sQPkFC_Iu0Jc0Fba4efoUYHcq- TBjLJgPQW-8aQVFMEobmMhkTJUUr0iXAibZV2Bbwd7HalGh1oZU07AtvQa7T- NMv7LUZT8rSYeSZ8kHBXKYaUHjVykVAAKmw2gS3ZDxpiklgSg8VmSyU6788JwH6lh2VpDzs1r0yoH55qOZD8gzBls64i5Lwgk Auth=DQAAAL8AAAD3PzwO5BSHo_TzqwD-QyTVM73-vxDAlUs8fkzbLoX5lHr6YI- D0IznRSnYoJshE9LDjtm78vcpbieT_RGBS9pnWXFier8l8uVQwITP0SLJnH2QMla4qLzylDANSqIIDdm_MY91t1wjGGivaTr5mOB_4w-0NQx_QvSQwyl-- eZnEkkH-80Ul_HJYzLv6TneYGd9q1q6UUAgDszesHzBQYullYvmwY1aF2wbVCUKF4urS_ynONL55aYg01ccShzExjs Content-Type: application/x-www-form-urlencoded Content-Length: 209 User-Agent: Jakarta Commons-HttpClient/3.1 Host: android.apis.google.com registration_id=APA91bEhZNjB1KZRlIzolrG_oXBpn0uTxPsoX22L5Xz- i9DTK38PRNe4QgoMTG9L4mrGlx33t6k39vRewVFRF7SAMbVSj62ESJ5o1gAdfANSiC6SCdXzAfEcollapse_key=12345data.receiver=1234data.source=12345data.message=holaHTTP/ 1.0411Length Required Content-Type: text/html; charset=UTF-8 Content-Length: 1363 Date: Mon, 27 Dec 2010 16:30:22 GMT Server: GFE/2.0 htmlhead meta http-equiv=content-type content=text/html;charset=utf-8 title411Length Required/title style!-- body {font-family: arial,sans-serif} div.nav {margin-top: 1ex} div.nav A {font-size: 10pt; font-family: arial,sans-serif} span.nav {font-size: 10pt; font-family: arial,sans-serif; font-weight: bold} div.nav A,span.big {font-size: 12pt; color: #cc} div.nav A {font-size: 10pt
Re: [android-developers] Re: c2DM error when third-party server sends data to push
= new Protocol(https, new EasySSLProtocolSocketFactory(), 443); HttpClient httpclient = new HttpClient(); httpclient.getHostConfiguration().setHost( android.apis.google.com, 443, myhttps); PostMethod httppost = new PostMethod(C2DM_URL); try { httppost.addRequestHeader(Authorization, GoogleLogin auth= + authToken); httppost.addRequestHeader(Content-Type, application/x-www-form- urlencoded); httppost.addParameter(registration_id, registrationID); httppost.addParameter(collapse_key, collapseKey); httppost.addParameter(data.receiver, destination); httppost.addParameter(data.source, source); httppost.addParameter(data.message, message); httppost.addRequestHeader(Content-Length, +httppost.getRequestEntity().getContentLength()); httpclient.executeMethod(httppost); return new String(httppost.getResponseBody()); } finally { httppost.releaseConnection(); } } I have tested all those headers and it does not work. Did you find anything? Is it possible to contact to some at C2DM project to see what happens? Thanks a lot! On Dec 24, 3:23 pm, Nagaraj Ramarao nraj.tes...@gmail.com wrote: Can someone knowledgable with C2DM help me resolve this issue please. Thanks Nagaraj On Thu, Dec 23, 2010 at 10:20 AM, nagaraj nraj.tes...@gmail.com wrote: I am trying to push data from my server hosting a webservice but I get the following error: htmlhead meta http-equiv=content-type content=text/html;charset=utf-8 title411Length Required/title style!-- body {font-family: arial,sans-serif} div.nav {margin-top: 1ex} div.nav A {font-size: 10pt; font-family: arial,sans-serif} span.nav {font-size: 10pt; font-family: arial,sans-serif; font-weight: bold} div.nav A,span.big {font-size: 12pt; color: #cc} div.nav A {font-size: 10pt; color: black} A.l:link {color: #6f6f6f} A.u:link {color: green} //--/style script!-- var rc=411; //-- /script /head body text=#00 bgcolor=#ff table border=0 cellpadding=2 cellspacing=0 width=100%trtd rowspan=3 width=1% nowrap bfont face=times color=#0039b6 size=10G/fontfont face=times color=#c41200 size=10o/fontfont face=times color=#f3c518 size=10o/fontfont face=times color=#0039b6 size=10g/fontfont face=times color=#30a72f size=10l/fontfont face=times color=#c41200 size=10e/fontnbsp;nbsp;/b tdnbsp;/td/tr trtd bgcolor=#3366ccfont face=arial,sans-serif color=#ffbError/b/td/tr trtdnbsp;/td/tr/table blockquote H1Length Required/H1 POST requests require a codeContent-length/code header. p /blockquote table width=100% cellpadding=0 cellspacing=0trtd bgcolor=#3366ccimg alt= width=1 height=4/td/tr/table /body/html Here is the java code that posts message to google c2dm which inturn will send a push notification to the device: private void postData(String auth, String id, String data) { DefaultHttpClient client = new DefaultHttpClient(); HttpPost httppost = new HttpPost( https://android.apis.google.com/c2dm/send;); ListNameValuePair formparams = new ArrayListNameValuePair(); formparams.add(new BasicNameValuePair(registration_id, id)); formparams.add(new BasicNameValuePair(data.payload, data)); formparams.add(new BasicNameValuePair(collapse_key, something)); //formparams.add(new BasicNameValuePair(Content-length, +data.length())); if (null != id) { formparams.add(new BasicNameValuePair(id, id)); } UrlEncodedFormEntity entity = null; try { entity = new UrlEncodedFormEntity(formparams, UTF-8); } catch (UnsupportedEncodingException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } httppost.setEntity(entity); Header header = new BasicHeader(Authorization: GoogleLogin auth=, auth); Header header2 = new BasicHeader(Content-length=, +data.length()); httppost.addHeader(header); httppost.addHeader(header2); httppost.getParams().setParameter(Content-length:, +data.length()); HttpContext localContext = new BasicHttpContext(); HttpResponse response = null; try { response = client.execute(httppost, localContext); HttpEntity entity2 = response.getEntity(); System.out.println(); System.out.println(response.getStatusLine()); Header[] headers
[android-developers] Re: c2DM error when third-party server sends data to push
Can someone knowledgable with C2DM help me resolve this issue please. Thanks Nagaraj On Thu, Dec 23, 2010 at 10:20 AM, nagaraj nraj.tes...@gmail.com wrote: I am trying to push data from my server hosting a webservice but I get the following error: htmlhead meta http-equiv=content-type content=text/html;charset=utf-8 title411 Length Required/title style!-- body {font-family: arial,sans-serif} div.nav {margin-top: 1ex} div.nav A {font-size: 10pt; font-family: arial,sans-serif} span.nav {font-size: 10pt; font-family: arial,sans-serif; font-weight: bold} div.nav A,span.big {font-size: 12pt; color: #cc} div.nav A {font-size: 10pt; color: black} A.l:link {color: #6f6f6f} A.u:link {color: green} //--/style script!-- var rc=411; //-- /script /head body text=#00 bgcolor=#ff table border=0 cellpadding=2 cellspacing=0 width=100%trtd rowspan=3 width=1% nowrap bfont face=times color=#0039b6 size=10G/fontfont face=times color=#c41200 size=10o/fontfont face=times color=#f3c518 size=10o/fontfont face=times color=#0039b6 size=10g/fontfont face=times color=#30a72f size=10l/fontfont face=times color=#c41200 size=10e/fontnbsp;nbsp;/b tdnbsp;/td/tr trtd bgcolor=#3366ccfont face=arial,sans-serif color=#ffbError/b/td/tr trtdnbsp;/td/tr/table blockquote H1Length Required/H1 POST requests require a codeContent-length/code header. p /blockquote table width=100% cellpadding=0 cellspacing=0trtd bgcolor=#3366ccimg alt= width=1 height=4/td/tr/table /body/html Here is the java code that posts message to google c2dm which inturn will send a push notification to the device: private void postData(String auth, String id, String data) { DefaultHttpClient client = new DefaultHttpClient(); HttpPost httppost = new HttpPost( https://android.apis.google.com/c2dm/send;); ListNameValuePair formparams = new ArrayListNameValuePair(); formparams.add(new BasicNameValuePair(registration_id, id)); formparams.add(new BasicNameValuePair(data.payload, data)); formparams.add(new BasicNameValuePair(collapse_key, something)); //formparams.add(new BasicNameValuePair(Content-length, +data.length())); if (null != id) { formparams.add(new BasicNameValuePair(id, id)); } UrlEncodedFormEntity entity = null; try { entity = new UrlEncodedFormEntity(formparams, UTF-8); } catch (UnsupportedEncodingException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } httppost.setEntity(entity); Header header = new BasicHeader(Authorization: GoogleLogin auth=, auth); Header header2 = new BasicHeader(Content-length=, +data.length()); httppost.addHeader(header); httppost.addHeader(header2); httppost.getParams().setParameter(Content-length:, +data.length()); HttpContext localContext = new BasicHttpContext(); HttpResponse response = null; try { response = client.execute(httppost, localContext); HttpEntity entity2 = response.getEntity(); System.out.println(); System.out.println(response.getStatusLine()); Header[] headers = response.getAllHeaders(); for (int i = 0; i headers.length; i++) { System.out.println(headers[i]); } System.out.println(); if (response.getEntity() != null) { System.out.println(EntityUtils.toString(response.getEntity())); } } catch (Exception e) { System.err.println(e); } finally { } } Note: 1. I successfully got the registration id from the client (device) 2. I successfully get the Auth from an earlier post on the server side Any help will be greatly appreciated Thank you -Nagaraj -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en