Xamarin.Forms 中的 HTTP 发布

Http Posting in Xamarin.Forms

我在通过参数化 url 从我的 Entires 发布数据时遇到问题,我不知道为什么会这样,URL returns 发布后的特定消息,下面是我的 URL :

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 消息中 return 一条消息之后提交条目中的数据。

直到你弄清楚为什么 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();