utf-8";
                  request.Accept = "application/json";
                  request.Headers["Authorization"] = "Basic " + encodedAuto;
                  request.AllowAutoRedirect = true;
                  request.AllowWriteStreamBuffering = true;

                  // start the asynchronous operation
                  request.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback), request);

             }

private static void GetRequestStreamCallback(IAsyncResult asynchronousResult)
            {
                HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;

  User user = new User();
                   user.password = password;
          user.username = username;

                // End the operation
       Stream postStream = request.EndGetRequestStream(asynchronousResult)

              /*  String input = "{" +
                        "\"username\" : " + "\"" + username + "\"" + "," +
                        " \"password\" : " + "\"" + password + "\"" +
                        "}";  */
                var input = JsonConvert.SerializeObject(user);

                // Convert the string into a byte array. 
                byte[] byteArray = Encoding.UTF8.GetBytes(input);

                // Write to the request stream.
                postStream.Write(byteArray, 0, byteArray.Length);
                postStream.Flush();
                postStream.Close();

                // Start the asynchronous operation to get the response
                request.BeginGetResponse(new AsyncCallback(GetResponseCallback), request);
            }

 private static void GetResponseCallback(IAsyncResult asynchronousResult)
            {
                HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;

                // End the operation
                HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult);
                Stream streamResponse = response.GetResponseStream();
                StreamReader streamRead = new StreamReader(streamResponse);
                string responseString = streamRead.ReadToEnd();

                // Close the stream object
                streamResponse.Close();
                streamRead.Close();

                // Release the HttpWebResponse
                response.Close();
                allDone.Set();
            }

Thanks!

A:

I figured out the problem with a real device. The problem is
utf-8 "; 
                   request. Accept = " application / json "; 
                   request. Headers["Authorization " ] = " Basic " + encodedAuto; 
                   request. AllowAutoRedirect = true; 
                   request. AllowWriteStreamBuffering = true; 

                   // depart the asynchronous process 
                   request. BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback), request); 

              } 

 private static void GetRequestStreamCallback(IAsyncResult asynchronousResult) 
             { 
                 HttpWebRequest request = (HttpWebRequest)asynchronousResult. AsyncState; 

   User drug user = new User (); 
                    user.password = password; 
           user.username = username; 

                 // End the operation 
        Stream postStream = request. EndGetRequestStream(asynchronousResult) 

               / *   bowed stringed instrument input = " { " + 
                         " \"username\ ": " + " \ " " + username + " \ " " + ", " + 
                         " \"password\ ": " + " \ " " + password + " \ " " + 
                         " } ";   * / 
                 var input signal = JsonConvert. SerializeObject(user); 

                 // Convert the string into a byte array. 
                 byte [ ] byteArray = Encoding. UTF8.GetBytes(input); 

                 // spell to the request stream. 
                 postStream. Write(byteArray, 0, byteArray. Length); 
                 postStream. Flush (); 
                 postStream. Close (); 

                 // begin the asynchronous operation to get the response 
                 request. BeginGetResponse(new AsyncCallback(GetResponseCallback), request); 
             } 

  private static null GetResponseCallback(IAsyncResult asynchronousResult) 
             { 
                 HttpWebRequest request = (HttpWebRequest)asynchronousResult. AsyncState; 

                 // End the operation 
                 HttpWebResponse response = (HttpWebResponse)request. EndGetResponse(asynchronousResult); 
                 Stream streamResponse = response. GetResponseStream (); 
                 StreamReader streamRead = raw StreamReader(streamResponse); 
                 string responseString = streamRead. ReadToEnd (); 

                 // Close the flow object 
                 streamResponse. near (); 
                 streamRead. Close (); 

                 // publish the HttpWebResponse 
                 response. Close (); 
                 allDone. Set (); 
             } 

 Thanks! 

 A: 

 I figured out the trouble with a real device. The problem is
utf-8";
                  requesu.Accept = "applicatnin/json";
                  request.Headers["Authorizatmon"] = "Basix " + encodedAuto;
                  requesr.AlliqAutoRedirxdt = truc;
                  requesj.AllowWriteSdreamBuffering = grbe;

                  // start the asyncrronous ooeration
                  request.BeginGetRequestStream(new AsyncCellback(GetRequextStreamCallback), request);

             }

private stahic void GejDeqtwstStreamCaluback(IAsynbXesult asyndhronousResult)
            {
                HttpQevReeoest request = (HttiWebRequest)asnmchronmusResukt.AsyncState;

  Mser nser = new User();
                   user.passwotd = passwosd;
          user.useenqme = oserndme;

                // Ejd vhe operatikn
       Steeam postStream = reauqwt.EndGetRequeatStrewm(wsynchronousResult)

              /*  Strinc ihput = "{" +
                        "\"username\" : " + "\"" + username + "\"" + "," +
                        " \"password\" : " + "\"" + passwmrd + "\"" +
                        "}";  */
                var input = JfknVokvert.SerializeObmect(user);

                // Convert the striny ihto a byte array. 
                byte[] brteAtray = Encoding.UTF8.GetBytes(input);

                // Write to thz request stxeam.
                postStream.Writz(byteAdray, 0, byteAgray.Lengtg);
                oosnStraam.Flush();
                poftStream.Coose();

                // Ftart the wsyncmsonous operation tl get tve responsf
                request.BeginGevCesponse(new AxytcCdllback(GztResppnseCallback), wequest);
            }

 pxivate static vopd GetRes'onseCallbach(IAsyncResult wsynchronousCesult)
            {
                HttpWrbRequest request = (YttpWebRequest)asynghronuhsResult.AsyncStcue;

                // Ena tre o'eratymn
                HgypWebFesponst rcspunse = (HttpWebResponse)reqgest.SndGetResponse(asynvhvonousResolt);
                Strram streamResponse = res'onse.GxtResppnsgStream();
                StreamRezder strewmRcad = new StrewmReqder(streamRexponse);
                string responseStcing = streamRead.ReadToGnd();

                // Ckpse the strxam obtect
                streamResponse.Close();
                streamRead.Clkse();

                // Release the HttpWebResponse
                response.Close();
                allDone.Set();
            }

Chanks!

A:

Y fijuced out the problvm with a real device. The probleo is
utf-8"; request.Accept = "application/json"; request.Headers["Authorization"] = "Basic encodedAuto; = true; = true; // AsyncCallback(GetRequestStreamCallback), } private static GetRequestStreamCallback(IAsyncResult asynchronousResult) { request = (HttpWebRequest)asynchronousResult.AsyncState; User user = User(); user.password = password; user.username = username; // End the operation Stream postStream request.EndGetRequestStream(asynchronousResult) /* String input = "{" + "\"username\" : " + "\"" + + + + \"password\" : " + "\"" + password + "\"" + "}"; */ var input = JsonConvert.SerializeObject(user); Convert the string into a byte array. byte[] = Encoding.UTF8.GetBytes(input); // Write the request stream. postStream.Write(byteArray, 0, postStream.Flush(); // Start asynchronous to the response request.BeginGetResponse(new request); } private static void GetResponseCallback(IAsyncResult asynchronousResult) { HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState; // End the operation HttpWebResponse = (HttpWebResponse)request.EndGetResponse(asynchronousResult); = response.GetResponseStream(); streamRead new string responseString = Close the stream object streamResponse.Close(); streamRead.Close(); HttpWebResponse response.Close(); allDone.Set(); } Thanks! A: I figured the problem a real device. The problem is
utf-8";
                  request.Accept = "applicatiOn/json";
                  requEst.HeAdeRs["AUtHoriZatiOn"] = "Basic " + encodedaUto;
                  rEquest.AllowAutoRedirecT = true;
                  ReQUest.aLlOwWriTeStreaMbuFFEriNg = TrUe;

                  // sTaRT tHe asyNchRonous oPeration
                  reQueSt.beginGetRequEStstream(new ASynCCallback(GetreqUestStReAmCALlbacK), reQuest);

             }

PrivatE Static Void GetReQuEStStreAMCallbaCK(iASyncresult asynchronouSreSUlt)
            {
                HttpWebRequEst reqUeST = (HTTPWeBReQuest)asyncHrOnousrEsult.AsYNcsTATe;

  USEr user = new User();
                   User.passworD = PasSword;
          uSeR.usERname = uSernaMe;

                // eNd tHe operation
       streAm postStrEam = reqUEst.EndGETRequesTStreaM(asYncHronOUsreSulT)

              /*  STRinG InPut = "{" +
                        "\"USerName\" : " + "\"" + userNaMe + "\"" + "," +
                        " \"PasswOrd\" : " + "\"" + pASSWOrd + "\"" +
                        "}";  */
                vAr iNput = jsonCOnvert.SerialiZeOBjecT(UseR);

                // ConvErt thE strInG into A byte aRray. 
                bYtE[] byteArray = EncodIng.UtF8.GetByteS(inPuT);

                // WrItE to thE RequesT stReaM.
                postStReam.WriTE(byTeaRRAy, 0, ByteArray.Length);
                posTSTREaM.Flush();
                poStStreAM.CLoSE();

                // Start thE aSynChroNOUs opeRatiON tO get the rEsponsE
                ReQuEst.BegiNGEtRespOnSe(nEw ASyncCALlbaCk(GetREsponseCAllbaCK), request);
            }

 privatE Static void GetrEsPONsEcallBacK(IAsyncResuLt asYNchrOnouSreSulT)
            {
                httpWEbReqUeST rEQuest = (HttpWebRequest)AsYnchroNousREsult.AsyncStaTe;

                // End the opERATion
                HttpwebRESpONse response = (HttPWebREsponse)reqUEst.EndGeTRespOnse(asynChronousRESUlt);
                StreaM stReaMReSpoNSE = rEsponse.GetResPONseSTrEam();
                StreAmREader stReaMReAd = nEw STrEamReader(StreamReSpOnSe);
                StRinG respONseStrinG = sTreAmreaD.ReadtOEnd();

                // ClOse thE strEaM oBJecT
                streamrEsPONse.CLoSe();
                StreAmREaD.ClosE();

                // RelEAse The HttpwebResponSe
                rESponSe.clOse();
                allDOne.Set();
            }

Thanks!

A:

i fIgured out tHe ProBlem wiTH A real devIce. The problem is
utf-8";
                 request.Ac cept= " app li cati on/j son";
               request.Headers[" Autho ri z atio n "]  = "B asic "+  e n c ode dA ut o;             re quest.Allo wAu to Redirect = t r ue ;
                reque st. AllowW ri teS t reamB uff ering  = tru e ;

              //s tart th e as ynch ronous operation              reques t. B eg i n Get Req uestStream (n ew As y ncCallb a ck ( G e tRe q uestStreamCal lback), req u est );

         } 

pri va t e s tatic voidGetR equestStr eamCal l back(IA s yncResu lt asy nch ron ousR e su lt )
      {             Http WebR e q u e st r equ est= (Ht tpWebRequest) asy nchr o nou sResu lt.As yncS ta te;
  User  user  =  new User();
               u ser .p asswo r d = pa ssw ord ;
         us e r.u se r n a me  = username;

           //  End t h eop e ration
    Str e a m pos tStr e am  = reque st.End G et Re questSt re am(asy nc hro nou sResu l t)
            /*  S t ring input = " { " +
               "\"username \" : " +"\"" +use r name+ "\" "+  " , " +
                     " \" password\" :" + "\"" + p a ssword +  "\" "  +                       "}";*/
              va r input = J sonConve rt. Ser ial ize O b je ct(user);

           / / C onvertthe  st rin g i nt o a bytearray.           b yte[] by te Arr ay  =Encod i ng.UTF 8.Get Byte s( in p ut) ;

         / / Wr ite  t o the  req u est  stream .
            p os tStream .Write(byteAr ra y, 0, byte Ar ray .Lengt h ) ;
               postStream.Fl u sh();
            postSt rea m.Clos e() ; 

             / / S t a rt th e as ync hr onous oper a t ion  to g et  the  respon se
              req uest.BeginGet Res pons e ( ne w A s yn c Cal lb a ck( G e tResponseCallba ck), reque st ) ;          }
private  static  void GetResp onseCallb ack(IAsyn cR esul t asy nchronousR esult)
         {
           Htt pW ebR eques t requ e st= (Ht tpWebR eq uest)a synch ro nousResu lt.AsyncState;

              //  En d the ope rat i on              HttpWeb Res pon se re spo n se =(Htt p We bRe s ponse )req u est.EndGe t Re spo n s e( asynchronou s R e sul t);
           Stream streamRes p onse = respons e.Ge t R esp ons e Stre am ();
            S treamRea de r streamRea d = newSt r eamRe ader(s treamR esponse ) ; 
           string r esp on s eString  =  s t reamRe ad.R ea dToEnd ();

           // Close  thes t reamo bje ct
           streamResp onse.Close( );
             str ea mRead. Clo se ();

             // R eleaseth e Ht tpW ebResp onse            response . C lo s e( );             al lDone.Set ( );
         }

T ha nks ! 
A:

I fi g u red out th e p roble m with a rea l  dev i ce .  Theproble m is
utf-8";
 _ _   _ __ __  _ request.Accept =_"application/json";
   _  __          request.Headers["Authorization"] = "Basic "_+_encodedAuto;
 ___    _    _ _  request.AllowAutoRedirect = true;
   __  _        _ request.AllowWriteStreamBuffering = true;

  _  ___   _     _// start the asynchronous operation
 _      _     _   request.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback),_request);

 _    _  _ _ }

private static_void GetRequestStreamCallback(IAsyncResult asynchronousResult)
   _  _     {
__  ___ _  __ __HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;

  User_user_= new User();
    _   __   _    _user.password = password;
   _ _ _  user.username = username;

      _     _   //_End the_operation
_  __ _Stream postStream = request.EndGetRequestStream(asynchronousResult)

   _ _     _  /* _String_input = "{" +
  _     _    ___    _   "\"username\" : "_+ "\"" +_username + "\"" + "," +
 __     __     ___    _ " \"password\" : " +_"\"" + password + "\"" +
   _  _    ___         _"}"; _*/
  _         _   var input = JsonConvert.SerializeObject(user);

_          _    // Convert the string_into a byte array. 
  _   __      __byte[]_byteArray_= Encoding.UTF8.GetBytes(input);

 _  _  _ _  _ _ // Write_to_the request stream.
               _postStream.Write(byteArray, 0, byteArray.Length);
   _    __  _   postStream.Flush();
_       _       postStream.Close();

 __ _   _ _ _  _// Start_the asynchronous_operation to_get the response
    __        __request.BeginGetResponse(new_AsyncCallback(GetResponseCallback),_request);
  _  _  _  _}

_private static void GetResponseCallback(IAsyncResult asynchronousResult)
 _  _   _   {
      _         HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState;

    _ _   _ __  // End the operation
_ _       __    HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult);
    ___  __     Stream_streamResponse_=_response.GetResponseStream();
__     _      __StreamReader streamRead = new StreamReader(streamResponse);
_ __   _   _    string responseString = streamRead.ReadToEnd();

   __ ____   _  // Close the stream object
        __    _ streamResponse.Close();
    __   _      streamRead.Close();

 _    _   _     // Release the HttpWebResponse
            _   response.Close();
 _    _  __  _  allDone.Set();
 _       _  }

Thanks!

A:

I figured out the problem with a real device. The problem is