php - windows phone 8 c# httpclient dosent send request for second time -
i trying simple app in windows phone 8.1. have button , on first time click send request insert data database via url in php. on second click delete data same table in database via url in php. when first run it. send me following response httpclient response
statuscode:200, reasonphase:'ok', version:0.0,content: system.net.http.streamcontent,headers: { date:thu,04 jun 2015 08:29:50 gmt server:apache server:phusion_passage/4.0.10 server: mod_bwlimited/1.4/5 server:mod_fcgid/2.3.9 x-powered-by:php/5.4/5.4.36 keep-alive:timeout=3,max=30 connection:keep-alive transfer-encoding:chunked content-type:text/html }
and on second click same response deleting. if again press button how following msg
statuscode:200, reasonphase:'ok', version:0.0,content: system.net.http.streamcontent,headers: { x-powered-by:php/5.4/5.4.36 keep-alive:timeout=3,max=30 transfer-encoding:chunked content-type:text/html }
and no data inserted database.
i in emergency launch small part of big project. code follows:
declaration:
url = "http://demo.in/customer_info.php?"; url_delete = "http://demo.in/delete_noti.php?device_id="; data1 = url + "device_id=4000"; data_delete = url_delete + "4000";
method:
private async void senddata(string data) { // messagebox.show(data1); using (httpclient hc = new httpclient()) { var response = await hc.getasync(data); messagebox.show(response.tostring()); hc.dispose(); } } private async void deletedata(string data) { //messagebox.show(url_delete1); using (httpclient hc = new httpclient()) { var response = await hc.getasync(data); //messagebox.show(hc1.tostring()); messagebox.show(response.tostring()); hc.dispose(); } }
usage:
private void btn_click(object sender, routedeventargs e) { if (count == 0) { senddata(data1); (sender button).background = new solidcolorbrush(system.windows.media.color.fromargb(225, 247, 98, 15)); messagebox.show("sending"); // suspend(a); count = 1; } else { deletedata(url_delete); (sender button).background = new solidcolorbrush(colors.black); messagebox.show("deleting"); count = 0; } }
as @null pointer suggested, might caching issue.
you can add random parameter url said or can add line of code ignore cache if don't or can't add parameter url:
hc.defaultrequestheaders.ifmodifiedsince = datetime.now;
Comments
Post a Comment