java.io.IOException: Server returned HTTP response code: 403 for URL: https://www.google.com/accounts/ClientLogin

3,885 views
Skip to first unread message

prateek shukla

unread,
May 12, 2011, 5:57:02 AM5/12/11
to android-c2dm
Here is my code....
public void getAuthentification() {
System.out.println("check");
//HttpPost post = new HttpPost("https://www.google.com/accounts/
ClientLogin");
try {

System.getProperties().put("proxySet", true);
System.getProperties().put("proxyHost","proxyMY" );
System.getProperties().put("proxyPort","8080");

System.out.println("getAuthentication method
called****************************");
URL url=new URL("https://www.google.com/accounts/ClientLogin");

URLConnection connection=url.openConnection();
connection.setDoOutput(true);

HttpURLConnection conn=(HttpURLConnection)connection;
BufferedWriter out = new BufferedWriter( new
OutputStreamWriter( conn.getOutputStream() ) );
out.write("Email=x...@gmail.com\r\n");
out.write("Passwd=12345\r\n");
out.write("accountType=GOOGLE\r\n");
out.write("source=MY_APP-V0.1\r\n");
out.write("service=ac2dm\r\n");
System.out.println("here");
BufferedReader rd = new BufferedReader(new
InputStreamReader(conn.getInputStream()));
System.out.println("getAuthentication method called2");
String line = "";
while ((line = rd.readLine()) != null) {
System.out.println(line);
System.out.println("inside");
if (line.startsWith("Auth=")) {
key=line.substring(5);
System.out.println(line.substring(5));
System.out.println("something to be done here..");

}
}
}
catch(IOException e) {
e.printStackTrace();
}
}
}

Getting this error:::


java.io.IOException: Server returned HTTP response code: 403 for URL:
https://www.google.com/accounts/ClientLogin
at
sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:
1290)
at
sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:
234)
at
com.tcs.mobility.android.c2dm.Server.getAuthentification(Server.java:
75)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
org.apache.axis.providers.java.RPCProvider.invokeMethod(RPCProvider.java:
397)
at
org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider.java:
186)
at
org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:
323)
at
org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:
32)
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
at org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:
454)
at org.apache.axis.server.AxisServer.invoke(AxisServer.java:281)
at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:
699)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at
org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:
327)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:
290)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:
206)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:
233)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:
191)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:
128)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:
102)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:
109)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:
293)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:
849)
at org.apache.coyote.http11.Http11Protocol
$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:
454)
at java.lang.Thread.run(Thread.java:619)
.
.
.
.
.
some one please help..

Thanks in advance....

abdul waheed

unread,
May 12, 2011, 6:07:47 AM5/12/11
to androi...@googlegroups.com
HI,
http://waheedtechblog.blogspot.com/2011/05/clientlogin-for-installed-applications.html

Hope this help you...
--
Thanks and Regards
Abdul Waheed



prateek shukla

unread,
May 12, 2011, 1:22:41 PM5/12/11
to android-c2dm
Thanks a lot ...

It was really helpful...

It's working now...

I am facing similar probleb with the server send message code too.
Can you please help with that?

Thanks and regards,
Prateek

On May 12, 3:07 pm, abdul waheed <abdulwahee...@gmail.com> wrote:
> HI,http://waheedtechblog.blogspot.com/2011/05/clientlogin-for-installed-...
>
> <http://waheedtechblog.blogspot.com/2011/05/clientlogin-for-installed-...>Hope
> this help you...
>
> On Thu, May 12, 2011 at 3:27 PM, prateek shukla <prateeks...@gmail.com>wrote:
>
>
>
> > Here is my code....
> > public void getAuthentification() {
> >                System.out.println("check");
> >                //HttpPost post = new HttpPost("
> >https://www.google.com/accounts/
> > ClientLogin");
> >                try {
>
> >                        System.getProperties().put("proxySet", true);
> >                        System.getProperties().put("proxyHost","proxyMY" );
> >                        System.getProperties().put("proxyPort","8080");
>
> >                        System.out.println("getAuthentication method
> > called****************************");
> >                        URL url=new URL("
> >https://www.google.com/accounts/ClientLogin");
>
> >                        URLConnection connection=url.openConnection();
> >                        connection.setDoOutput(true);
>
> >                        HttpURLConnection
> > conn=(HttpURLConnection)connection;
> >                        BufferedWriter out = new BufferedWriter( new
> > OutputStreamWriter( conn.getOutputStream() ) );
> >                        out.write("Email=...@gmail.com\r\n");
> >                        out.write("Passwd=12345\r\n");
> >                        out.write("accountType=GOOGLE\r\n");
> >                        out.write("source=MY_APP-V0.1\r\n");
> >                        out.write("service=ac2dm\r\n");
> >                        System.out.println("here");
> >                        BufferedReader rd = new BufferedReader(new
> > InputStreamReader(conn.getInputStream()));
> >                        System.out.println("getAuthentication method
> > called2");
> >                        String line = "";
> >                        while ((line = rd.readLine()) != null) {
> >                                System.out.println(line);
> >                                System.out.println("inside");
> >                                if (line.startsWith("Auth=")) {
> >                                        key=line.substring(5);
>
> >  System.out.println(line.substring(5));
> >                                        System.out.println("something to be
> > done here..");
>
> >                                }
> >                        }
> >                }
> >                catch(IOException e) {
> >                        e.printStackTrace();
> >                }
> > }
> > }
>
> > Getting this error:::
>
> > java.io.IOException: Server returned HTTP response code: 403 for URL:
> >https://www.google.com/accounts/ClientLogin
> >        at
>
> > sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection....
> > 1290)
> >        at
>
> > sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConn...

abdul waheed

unread,
May 12, 2011, 11:41:27 PM5/12/11
to androi...@googlegroups.com
Thats great.

try
     {
     System.out.println("Sending Message"); 
                    
                    // Create a new HttpClient and Post Header 
                    HttpClient httpclient = new DefaultHttpClient(); 
                    HttpPost httppost = new HttpPost("https://android.apis.google.com/c2dm/send"); 
                    httppost.addHeader("Authorization", "GoogleLogin auth="+authToken); 
                    httppost.addHeader("Content-Type","application/x-www-form-urlencoded"); 
                                           
                            // Add your data 
                            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); 
                           
                            nameValuePairs.add(new BasicNameValuePair("registration_id",regId)); 
                            nameValuePairs.add(new BasicNameValuePair("collapse_key", "TEST")); 
                             
                            nameValuePairs.add(new BasicNameValuePair("data.message","Message Sent"));//Here message is the <Key> 
                             httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs,"UTF-8")); 
                            
                            // Execute HTTP Post Request 
                            System.out.println("Executing  sendMessage"); 
                            
                        
                            HttpResponse response = httpclient.execute(httppost); 
                           
                            System.out.println(response.getStatusLine()); 
                     
                             
                              if (response.getEntity() != null) 
                              { 
                              System.out.println(EntityUtils.toString(response.getEntity())); 
                              }
                               
                    } 
                    
                    catch (ClientProtocolException e) 
                    { 
                     System.out.println("ClientProtocolException"+e);
                     // TODO Auto-generated catch block 
                    } catch (IOException e) 
                    { 
                        System.out.println("IOException"+e);    
                     // TODO Auto-generated catch block 
                    } 
                    catch(Exception e)
                    {
                     System.out.println("Exception"+e);
                    }
                  
            } 

Enjoy!!!

prateek shukla

unread,
May 13, 2011, 12:53:45 AM5/13/11
to android-c2dm
Thanks a lot for this one too ...

But this code is not working for me...

It gets stuck at this line

HttpClient httpclient = new DefaultHttpClient();

with out any exception...


For the auth code generation too the second code was working for
me..not the first one where you used http client...

Can you please tell you it gets stuck at http client....??

Thanks and regards,
Prateek
> > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImp­l.java:
> > org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applicatio­nFilterChain.java:
> > > > 290)
> > > >        at
>
> > org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterC­hain.java:
> > > > 206)
> > > >        at
>
> > org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.j­ava:
> > > > 233)
> > > >        at
>
> > org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.j­ava:
> > > > 191)
> > > >        at
>
> > org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:
> > > > 128)
> > > >        at
>
> > org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:
> > > > 102)
> > > >        at
>
> > org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.jav­a:
> Abdul Waheed- Hide quoted text -
>
> - Show quoted text -

abdul waheed

unread,
May 13, 2011, 1:06:43 AM5/13/11
to androi...@googlegroups.com
Hey 
This code work well on Apache Server but there is some issues while runnig on Google App Engine..I ll post the bolg then i will mail you the link...

prateek shukla

unread,
May 13, 2011, 1:14:58 AM5/13/11
to android-c2dm
Hey thanks,
I will wait for your blog post...

Thanks a lot for all your help..

Thanks and regards,
Prateek


On May 13, 10:06 am, abdul waheed <abdulwahee...@gmail.com> wrote:
> Hey
> This code work well on Apache Server but there is some issues while runnig
> on Google App Engine..I ll post the bolg then i will mail you the link...
>
> ...
>
> read more »- Hide quoted text -

prateek shukla

unread,
May 13, 2011, 2:47:23 AM5/13/11
to android-c2dm


On May 13, 10:14 am, prateek shukla <prateeks...@gmail.com> wrote:
> Hey thanks,

By using the Url of google www.android.apis.google.com/ac2dm/send.
getting the protocol exception in this manner


- <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/
envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <soapenv:Body>
- <soapenv:Fault>
<faultcode>soapenv:Server.userException</faultcode>
<faultstring>java.lang.RuntimeException:
javax.net.ssl.SSLHandshakeException:
java.security.cert.CertificateException: No subject alternative DNS
name matching android.apis.google.com found.</faultstring>
+ <detail>
<ns1:hostname xmlns:ns1="http://xml.apache.org/axis/">01HW333135</
ns1:hostname>
</detail>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>

abdul waheed

unread,
May 17, 2011, 1:57:47 AM5/17/11
to androi...@googlegroups.com
Hi,
If you like the post..Please do comment there too..
http://waheedtechblog.blogspot.com/2011/05/third-party-applcation-server.html

Reply all
Reply to author
Forward
0 new messages