我收到错误:“当使用下面的代码时,基础连接已关闭,发送时发生意外错误”tRequest.GetResponse()上会抛出异常;
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();
答案 0 :(得分:0)
事实证明,我们的网络团队在网络级别阻止了gcm。网络配置更改后,我已成功拨打gcm。