1
我遇到錯誤:在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();