【问题标题】:Http Posting in Xamarin.FormsXamarin.Forms 中的 Http 发布
【发布时间】:2017-12-10 05:57:43
【问题描述】:

我在通过参数化 url 从我的 Entires 发布数据时遇到问题,我不知道为什么会这样,该 URL 在发布后返回一条消息,下面是我的 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 消息中返回一条消息。

【问题讨论】:

  • 您的示例显示的是 GET,而不是 POST。您确定需要使用 POST 吗?您代码中的参数名称也与示例 url 中显示的名称不匹配。
  • 是的,我想发帖@Jason

标签: c# forms xamarin.forms http-post xamarin.forms.entry


【解决方案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();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-27
    • 2017-06-28
    • 1970-01-01
    • 1970-01-01
    • 2016-07-03
    相关资源
    最近更新 更多