android - 为什么真实设备上的xamarin android应用程序总是抛出错误但在模拟器上工作
问题描述
我有一个奇怪的问题。我一直在使用 xamarin 表单开发一个应用程序,该表单在后端使用用 php 编写的 API。该应用程序的 iOS 版本运行良好,Android 版本在模拟器上运行良好。当我在真实设备上存档并安装 apk 文件时,它总是会为所有 api 函数抛出错误。找不到原因,哪里出错了。
仅在发布模式下使用 armeabi-v7a 和链接选项将我的 apk 文件归档为用户和 Sdk 程序集。
我是否缺少为归档项目而设置的任何属性?
任何帮助,将不胜感激。
public async void OnLogin()
{
string url = "http://www.example.com/UserController/login";
HttpClient client = new HttpClient();
object userjson = new
{
email = Email.Text.ToLower(),
password = Password.Text
};
var myContent = JsonConvert.SerializeObject(userjson);
Console.WriteLine("Post Content" + myContent);
var buffer = System.Text.Encoding.UTF8.GetBytes(myContent);
var byteContent = new ByteArrayContent(buffer);
byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
Console.WriteLine("Inside Login() Method");
Console.WriteLine("Json Content::" + myContent);
Console.WriteLine("Json Byte::" + byteContent.ReadAsStringAsync());
var response = await client.PostAsync(url, byteContent).ConfigureAwait(false);
var code = response.StatusCode;
Console.WriteLine("Code::" + code);
if (code.ToString() == "OK")
{
string res = response.Content.ReadAsStringAsync().Result;
App.serverToken = "activated";
App.Current.Properties["Token"] = App.serverToken;
await Application.Current.SavePropertiesAsync();
isValid = true;
Console.WriteLine("Token::" + App.serverToken);
}
else
{
isValid = false;
Device.BeginInvokeOnMainThread(() =>
{
LoginFaild.Text = "InCorrect Email or Password";
Email.Text = string.Empty;
Password.Text = string.Empty;
});
}
}
这是使用 Postasync 访问 API 的方法。
解决方案
推荐阅读
- php - 限制多个foreach
- java - appium 在查找非常长的可访问性 id 元素时遇到问题
- java - 这个算法的大 O 符号是什么?
- directx-9 - DX9 GenerateMipSubLevels 产生损坏的 mipmap 并破坏帧率
- r - 如何将一串不同长度的数字和字母分成R中的不同列?
- sql - 带业务逻辑的索引视图
- python - 从列表中读取 csv 文件名并在脚本中使用它们
- android - 如何运行多个活动并关闭这些活动
- java - 限制 Rest 模板每分钟拨打的电话
- amazon-web-services - jenkins 中从 s3 存储桶到 aws codedeploy 的部署作业