2017-07-06 61 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();