我想在Windows Phone 8.1中使用一個簡單的應用程序。我有一個按鈕,並在第一次點擊它發送一個請求,通過在PHP中通過URL插入數據到數據庫。第二次點擊它通過php中的另一個url從數據庫中的相同表中刪除數據。當我第一次運行它。從HttpClient的響應windows phone 8 c#httpclient dosent第二次發送請求
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
}
送我下面的響應和對第二次點擊我也得到了刪除同樣的反應。如果我再次按下按鈕我一些如何獲得以下味精
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
}
而且顯然沒有數據插入到數據庫中。
我在緊急啓動它,因爲這是一個大項目的一小部分。 我的代碼如下:
聲明:
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";
方法:
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();
}
}
用法:
private void btn_click(object sender, RoutedEventArgs e)
{
if (count == 0)
{
sendData(data1);
(sender as 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 as Button).Background = new SolidColorBrush(Colors.Black);
MessageBox.Show("deleting");
count = 0;
}
}
這可能是一個緩存問題。嘗試通過向url添加額外的查詢參數。 url = url +「&ticks」+ dateTime.Now.Ticks –