GCMComminication错误底层连接已关闭在发送时发生意外错误
问题描述:
我遇到错误:在tRequest.GetResponse()引发异常时出现错误:“底层连接已关闭,使用下面的代码时发生了意外错误” ;GCMComminication错误底层连接已关闭在发送时发生意外错误
WebRequest tRequest = WebRequest.Create("https://android.googleapis.com/gcm/send");
tRequest.Method = "post";
tRequest.ContentType = " application/x-www-form-urlencoded;charset=UTF-8";
tRequest.Headers.Add(string.Format("Authorization: key={0}", applicationID));
int iRetryTime = 1;
if (NotificationRetryTime > 10)
iRetryTime = NotificationRetryTime - 10;
string postData =
"collapse_key=score_update&time_to_live=" + iRetryTime.ToString() + "&delay_while_idle=0&data.message="
+ value + "&data.time=" + System.DateTime.Now.ToString() + "®istration_id=" +
regId + "";
Byte[] byteArray = Encoding.UTF8.GetBytes(postData);
tRequest.ContentLength = byteArray.Length;
Stream dataStream = tRequest.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse tResponse = tRequest.GetResponse();
dataStream = tResponse.GetResponseStream();
StreamReader tReader = new StreamReader(dataStream);
String sResponseFromServer = tReader.ReadToEnd(); //Get response from GCM server.
tReader.Close();
dataStream.Close();
tResponse.Close();
答
事实证明,我们的网络团队在网络层面阻止gcm。网络配置更改后,我已成功进行gcm呼叫。