我有一个奇怪的问题。我一直在开发使用xamarin表单的应用程序,该应用程序使用后端用php编写的API。该应用程序的iOS版本运行良好,而android版本在模拟器上运行良好。当我在真实设备上存档并安装apk文件时,它对于所有api函数始终会引发错误。无法找到原因,哪里出了问题。
仅在发布模式下,使用armeabi-v7a和链接选项将用户和SDK程序集存档为我的apk文件。
我是否缺少为归档项目设置的任何属性?
任何帮助将不胜感激。
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的方法。