c# - unable to send data in windows phone 7 to php server through httpwebrequest -


application collects location coordinates , sends php server. coordinates getting displayed on emulator not getting saved on server.

here code:

private void post(string lat, string lng)         {             string latlng=lat;             httpwebrequest request = (httpwebrequest)webrequest.create("http://60.243.245.179/windowsapp/windows.php");             request.contenttype = "application/x-www-form-urlencoded";              // set method property 'post' post data uri.             request.method = "post";              // start asynchronous operation             request.begingetrequeststream(new asynccallback(getrequeststreamcallback), request);              // keep main thread continuing while asynchronous              // operation completes. real world application              // useful such updating user interface.              alldone.waitone();           }          private static void getrequeststreamcallback(iasyncresult asynchronousresult)         {             httpwebrequest request = (httpwebrequest)asynchronousresult.asyncstate;                // end operation             // convert string byte array.              byte[] bytearray = encoding.utf8.getbytes(lat);              stream poststream = request.endgetrequeststream(asynchronousresult);               // write request stream.             poststream.write(bytearray, 0, lat.length);            system.diagnostics.debug.writeline("->->", request);             poststream.close();              // start asynchronous operation response             request.begingetresponse(new asynccallback(getresponsecallback), request);           }           // =========================================================================         private void startlocationservice(geopositionaccuracy accuracy)         {             // reinitialize geocoordinatewatcher             mylocationwatcher = new geocoordinatewatcher(accuracy);             mylocationwatcher.movementthreshold = 20;              // add event handlers statuschanged , positionchanged events             mylocationwatcher.statuschanged += new eventhandler<geopositionstatuschangedeventargs>(watcher_statuschanged);             mylocationwatcher.positionchanged += new eventhandler<geopositionchangedeventargs<geocoordinate>>(watcher_positionchanged);              // start data acquisition             mylocationwatcher.start();         }          void watcher_statuschanged(object sender, geopositionstatuschangedeventargs e)         {             //the dispatcher dispatches specified method when status change occurs             deployment.current.dispatcher.begininvoke(() => mystatuschanged(e));          }          void mystatuschanged(geopositionstatuschangedeventargs e)         {             switch (e.status)             {                 case geopositionstatus.disabled:                     // location service disabled or unsupported.                     // alert user                     messagebox.show("location unsupported on device");                     break;             }         }          void watcher_positionchanged(object sender, geopositionchangedeventargs<geocoordinate> e)         {             //dispatcher invokes event position change.             deployment.current.dispatcher.begininvoke(() => mypositionchanged(e));         }          void mypositionchanged(geopositionchangedeventargs<geocoordinate> e)         {              // update textblocks show current location             lat = e.position.location.latitude.tostring("0.000");             system.diagnostics.debug.writeline(lat);            // messagebox.show(lat);             latitudetextblock.text = lat;             lng = e.position.location.longitude.tostring("0.000");             system.diagnostics.debug.writeline(lng);            // messagebox.show(lon);             longitudetextblock.text = lng;             post(lat,lng);         }            //==========================================================================          private static void getresponsecallback(iasyncresult asynchronousresult)         {             httpwebrequest request = (httpwebrequest)asynchronousresult.asyncstate;              // end operation             httpwebresponse response = (httpwebresponse)request.endgetresponse(asynchronousresult);              stream streamresponse = response.getresponsestream();             streamreader streamread = new streamreader(streamresponse);             string responsestring = streamread.readtoend();              // close stream object             streamresponse.close();             streamread.close();              // release httpwebresponse             response.close();             alldone.set();         } 

the request , response both take null values :( please anybody...


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -