java - Server returned HTTP response code: 400 for URL: https://gcm-http.googleapis.com/gcm/send -


i searched lot, didn't find way solve problem below.

enviando post para o gcm response code: 400 java.io.ioexception: server returned http response code: 400 url: https://gcm-http.googleapis.com/gcm/send @ sun.reflect.nativeconstructoraccessorimpl.newinstance0(native method) @ sun.reflect.nativeconstructoraccessorimpl.newinstance(nativeconstructoraccessorimpl.java:62) @ sun.reflect.delegatingconstructoraccessorimpl.newinstance(delegatingconstructoraccessorimpl.java:45) @ java.lang.reflect.constructor.newinstance(constructor.java:422) @ sun.net.www.protocol.http.httpurlconnection$10.run(httpurlconnection.java:1890) @ sun.net.www.protocol.http.httpurlconnection$10.run(httpurlconnection.java:1885) @ java.security.accesscontroller.doprivileged(native method) @ sun.net.www.protocol.http.httpurlconnection.getchainedexception(httpurlconnection.java:1884) @ sun.net.www.protocol.http.httpurlconnection.getinputstream0(httpurlconnection.java:1457) @ sun.net.www.protocol.http.httpurlconnection.getinputstream(httpurlconnection.java:1441) @ sun.net.www.protocol.https.httpsurlconnectionimpl.getinputstream(httpsurlconnectionimpl.java:254) @ br.com.farmas.util.post2gcm.post(post2gcm.java:46) @ br.com.farmas.main.appmain.main(appmain.java:17) caused by: java.io.ioexception: server returned http response code: 400 url: https://gcm-http.googleapis.com/gcm/send @ sun.net.www.protocol.http.httpurlconnection.getinputstream0(httpurlconnection.java:1840) @ sun.net.www.protocol.http.httpurlconnection.getinputstream(httpurlconnection.java:1441) @ java.net.httpurlconnection.getresponsecode(httpurlconnection.java:480) @ sun.net.www.protocol.https.httpsurlconnectionimpl.getresponsecode(httpsurlconnectionimpl.java:338) @ br.com.farmas.util.post2gcm.post(post2gcm.java:43) ... 1 more

could me please?

below, show code executing....

line 43 following: int responsecode = connection.getresponsecode();

enviando post para o gcm response code: 400 java.io.ioexception: server returned http response code: 400 url:      https://gcm-http.googleapis.com/gcm/send @ sun.reflect.nativeconstructoraccessorimpl.newinstance0(native method) @ sun.reflect.nativeconstructoraccessorimpl.newinstance(nativeconstructoraccessorimpl.java:62) @ sun.reflect.delegatingconstructoraccessorimpl.newinstance(delegatingconstructoraccessorimpl.java:45) @ java.lang.reflect.constructor.newinstance(constructor.java:422) @ sun.net.www.protocol.http.httpurlconnection$10.run(httpurlconnection.java:1890) @ sun.net.www.protocol.http.httpurlconnection$10.run(httpurlconnection.java:1885) @ java.security.accesscontroller.doprivileged(native method) @ sun.net.www.protocol.http.httpurlconnection.getchainedexception(httpurlconnection.java:1884) @ sun.net.www.protocol.http.httpurlconnection.getinputstream0(httpurlconnection.java:1457) @ sun.net.www.protocol.http.httpurlconnection.getinputstream(httpurlconnection.java:1441) @ sun.net.www.protocol.https.httpsurlconnectionimpl.getinputstream(httpsurlconnectionimpl.java:254) @ br.com.farmas.util.post2gcm.post(post2gcm.java:46) @ br.com.farmas.main.appmain.main(appmain.java:17) caused by: java.io.ioexception: server returned http response code: 400 url: https://gcm-http.googleapis.com/gcm/send @ sun.net.www.protocol.http.httpurlconnection.getinputstream0(httpurlconnection.java:1840) @ sun.net.www.protocol.http.httpurlconnection.getinputstream(httpurlconnection.java:1441) @ java.net.httpurlconnection.getresponsecode(httpurlconnection.java:480) @ sun.net.www.protocol.https.httpsurlconnectionimpl.getresponsecode(httpsurlconnectionimpl.java:338) @ br.com.farmas.util.post2gcm.post(post2gcm.java:43) ... 1 more 

below first code call

    public static void main(string[] args)  {     system.out.println("enviando post para o gcm");      post2gcm.post(api_key, criarcontent()); }  private static content criarcontent()  {     simpledateformat dateformat = new simpledateformat("yyyy-mm-dd hh:mm:ss");      content content = new content();     content.addregid("ecveu9f2lfm:apa91beb7anrtxp1owl_qrftluc35vxs2rgocpyaju5rtsupy427ihff8eayec3wthq54ag7q6mwbkuywohgvk_q-rth0qlgljjvqzh9b9x-gx6nli9_rjllrnwyv10iervfexfb3foy");     content.adddata("titulo", "titulo teste");     content.adddata("message", "message teste");     content.adddata("data", dateformat.format(new date()));     content.adddata("id", "2");      return content; } 

below second code exception happens. exception happens @ following line: int responsecode = connection.getresponsecode();

    public static void post(string apikey, content content)  {     try      {         url url = new url("https://gcm-http.googleapis.com/gcm/send");          httpurlconnection connection = (httpurlconnection) url.openconnection();          connection.setrequestmethod("post");          connection.setrequestproperty("content-type", "application/json");         connection.setrequestproperty("authorization", "key=" + apikey);          connection.setdooutput(true);          objectmapper mapper = new objectmapper();          dataoutputstream outputstream = new dataoutputstream(connection.getoutputstream());          mapper.writevalue(outputstream, content);          outputstream.flush();          outputstream.close();          int responsecode = connection.getresponsecode();         system.out.println("response code: " + responsecode);          bufferedreader bufferedreader = new bufferedreader(new inputstreamreader(connection.getinputstream()));          string linha = "";         stringbuffer resultado = new stringbuffer();         while ((linha = bufferedreader.readline()) != null)          {             resultado.append(linha);         }         bufferedreader.close();          system.out.println(resultado);     }      catch (malformedurlexception e)      {         e.printstacktrace();     }      catch (ioexception e)      {         e.printstacktrace();     } } 


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -