android - This property cannot be set after writing has started! on a C# WebRequest Object using GCM -


i want send data c# gcm , take bug.

code here:

 webrequest trequest;     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)); 

trequest.headers.add(string.format("sender: id={0}", sender_id));

 con.open();             //int ekleyen_id = convert.toint32(session["kullaniciid"].tostring());             sqlcommand cmd = new sqlcommand("select * users", con);             sqldatareader rd = cmd.executereader();             while (rd.read()) {                 string regidsend = rd["registered_id"].tostring();                 // string postdata = "{ 'registration_id': [ '" + regid + "' ], 'data': {'message': '" + txtmsg.text + "'}}";                 string postdata = "collapse_key=score_update&time_to_live=108&delay_while_idle=1&data.message=" + value + "&data.time=" + system.datetime.now.tostring() + "&registration_id=" + regidsend + "";                 console.writeline(postdata);                 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();                  //lblstat.text = sresponsefromserver;                 treader.close();                 datastream.close();                 tresponse.close(); 

you can't reuse webrequest. should create webrequest inside while loop.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -