为什么Xamarin.Form的httpClient.PostAsync在响应消息中没有$ _POST数据?

时间:2018-12-28 19:41:36

标签: c# xamarin.forms http-post

我可以在Xamarin Form应用程序中将HttpClient的{​​{1}}消息发送到Apache服务器,然后得到消息。那行得通而且很好,但是响应显示PostAsync为空。

$_POST$_SERVER['REQUEST_METHOD'],而POSTcount($_POST)

我在服务器端提供了一个小表格来测试POST提交。

(已删除HTML标记)

0

这适用于每个Web浏览器(例如Firefox,Chrome)

如果我调试Xamarin应用并查看html form name="postTest" action="https://www.mydomain.tld/" method="POST" input type="hidden" id="custId" name="custId" value="3487" input type="submit" value="Test Post" /form /html ,则可以看到JSON字符串。

JsonString

我已经在iOS和UWP下测试了Xamarin App。两者具有相同的结果。

PostAsync没有$ _POST数据。 WebView-> Form Post提交具有$ _POST数据。

我看不到任何问题。

更新

现在我有一个可用的UWP版本,但是iOS无法正常工作,并以GET方法发送?!

新版本使用.NET: Simplest way to send POST with data and read response中的代码

LoginData loginData = new LoginData
{
    Email = Application.Current.Properties["Email"].ToString(),
    Password = ((byte[])Application.Current.Properties["Password"]).ByteArrayToHexString()
};

string JsonString = loginData.ToJsonString();
System.Net.Http.StringContent stringContent = new System.Net.Http.StringContent(JsonString, Encoding.UTF8, "application/json");


HttpClient httpClient = new HttpClient();
try
{
    using (var httpResponse = await httpClient.PostAsync("https://www.mydomain.tld/", stringContent))
    {
        if (httpResponse.IsSuccessStatusCode)
        {
            string response = await httpResponse.Content.ReadAsStringAsync();

            if (response == null)
            {

            }
            else if (response == string.Empty)
            {

            }
            else
            {
                var browser = new WebView();

                var htmlSource = new HtmlWebViewSource();
                htmlSource.Html = response;
                browser.Source = htmlSource;
                this.Content = browser;
                await Task.Delay(30000);
            }
        }
    }
}
catch
{

}

0 个答案:

没有答案
相关问题