2017-07-06 64 views
0

現在面臨一個問題,通過參數化的URL發佈從我Entires數據發佈,我不知道爲什麼它的發生,網址張貼後返回一定的消息,下面是我的網址:的Http在Xamarin.Forms

http://bbs.eamobiledirectory.com/Mobile/MobileApi.aspx?Action=NewSalesReport&username=USERNAME&assID=ASSIGNID&repdetails=details&appoi_date=date

,這是怎麼了我發佈的數據:

void OnSubmitReport(object sender, System.EventArgs e) 
     { 
      PostData(); 
     } 


     public async void PostData() 
     { 


      string details = report_details_entry.Text; 
      string date = nextappointment_entry.Text; 


      var formContent = new FormUrlEncodedContent(new[] 
         { 
       new KeyValuePair<string, string>("unm", USERNAME), 
       new KeyValuePair<string, string >("assinID", ""+ASSIGNID), 
       new KeyValuePair<string, string>("details", details), 
       new KeyValuePair<string, string>("appoi_date", date) 

    }); 

      var response = await client.PostAsync("http://bbs.eamobiledirectory.com/Mobile/MobileApi.aspx?Action=NewSalesReport",formContent); 


     } 

我想是在條目提交數據後,病房我在DisplayAlert消息中返回的消息。

+0

您的例子顯示了一個GET ,而不是POST。你確定你需要使用POST嗎?代碼中的參數名稱也與示例url中顯示的名稱不匹配。 – Jason

+0

是的,我想發佈@Jason –

回答

1

直到你明白,爲什麼FormUrlEncodedContent不工作(我真的想知道爲什麼它不工作)

您可以通過發佈這樣解決問題:

var url = string.Format("http://bbs.eamobiledirectory.com/Mobile/MobileApi.aspx?Action=NewSalesReport&unm={0}&assignID={1}&report_details={2}&appoi_date={3}", 
       USERNAME, 
       ASSIGNID, 
       details, 
       date); 

var response = await client.PostAsync(url, null); 

var responseContent = await response.Content.ReadAsStringAsync();