Java GCM推送通知的http 411错误

Java GCM推送通知的http 411错误,java,android,Java,Android,我正在尝试点击gcm云以获取通知 我创建了web restfull web服务,实现了以下代码,但出现以下错误 String gurl = "https://android.googleapis.com/gcm/send"; URL url = new URL(gurl); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setRequestMethod("POST"); con.setRequestP

我正在尝试点击gcm云以获取通知

我创建了web restfull web服务,实现了以下代码,但出现以下错误

String gurl = "https://android.googleapis.com/gcm/send";
URL url = new URL(gurl);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("POST");

con.setRequestProperty("Authorization", "key=" + apikey);
con.setRequestProperty("registration_ids",regid);
con.setRequestProperty("data", "message="+msg);
con.setRequestProperty("Content-Length", "0");

con.setDoOutput(true);


int responseCode = con.getResponseCode();
System.out.println("\nSending 'POST' request to URL : " + url);
System.out.println("Response Code : " + responseCode);

BufferedReader in = new BufferedReader(
        new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();

while ((inputLine = in.readLine()) != null) {
    response.append(inputLine);
}
in.close();

// 7. Print result
System.out.println(response.toString());
//return response.toString();
return response.toString();
我得到的错误如下

VERE: The exception contained within MappableContainerException could not be mapped to a response, re-throwing to the HTTP container
java.io.IOException: Server returned HTTP response code: 411 for URL: https://android.googleapis.com/gcm/send
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at sun.net.www.protocol.http.HttpURLConnection$6.run(HttpURLConnection.java:1676)
at sun.net.www.protocol.http.HttpURLConnection$6.run(HttpURLConnection.java:1674)
at java.security.AccessController.doPrivileged(Native Method)
at sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:1672)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1245)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
at com.madhu.pack.SimpleWS.chattest1(SimpleWS.java:250)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
at 
等等

我正在发布来自android客户端的数据。你们能帮我解决这个问题吗?

错误代码411代表“所需长度”

你需要换行

con.setRequestProperty("Content-Length", "0");

您必须提交数据长度,而不是0。

请正确设置代码格式!