你好,我正在做一个Xamarin表单应用程序,它有一个登录屏幕,当用户输入用户名和密码,并点击登录按钮,它应该验证我的web服务。不过,这并不是说我只收到登录失败的消息
编辑:现在我在iOS上崩溃了,有以下错误:
此服务器的证书无效。您可能正在连接到一个假装为“service.brainstorminstruments.com”的服务器,这可能会使您的机密信息处于危险之中。
这是我的xaml代码:
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="LoginNavigation.LoginPage" Title="Login">
<ContentPage.ToolbarItems>
<ToolbarItem Text="Sign Up" Clicked="OnSignUpButtonClicked" />
</ContentPage.ToolbarItems>
<ContentPage.Content>
<StackLayout VerticalOptions="StartAndExpand">
<Label Text="Username" />
<Entry x:Name="usernameEntry" Placeholder="username" />
<Label Text="Password" />
<Entry x:Name="passwordEntry" IsPassword="true" />
<Button Text="Login" Clicked="OnLoginButtonClicked" />
<Label x:Name="messageLabel" />
</StackLayout>
</ContentPage.Content>
</ContentPage> 编辑我使用错误的类
这是后面的代码:
using System;
using System.Collections.Generic;
using System.Net.Http;
using Newtonsoft.Json;
using Xamarin.Forms;
namespace LoginNavigation
{
public partial class LoginPage : ContentPage
{
public LoginPage ()
{
InitializeComponent ();
}
async void OnSignUpButtonClicked (object sender, EventArgs e)
{
await Navigation.PushAsync (new SignUpPage ());
}
async void OnLoginButtonClicked (object sender, EventArgs e)
{
var postContent = new FormUrlEncodedContent(new[] {
new KeyValuePair<string, string>("username","usernameEntry"),
new KeyValuePair<string, string>("password","passwordEntry")
});
var httpClient = new HttpClient();
var serverResponse = await httpClient.PostAsync("https://service.brainstorminstruments.com/api/login", postContent);
var serverResponseString = await serverResponse.Content.ReadAsStringAsync();
//theEditor.Text = serverResponseString;
Response theResponseObject = JsonConvert.DeserializeObject<Response>(serverResponseString);
if (theResponseObject.status == "success") {
App.IsUserLoggedIn = true;
Navigation.InsertPageBefore (new MainPage (), this);
await Navigation.PopAsync ();
} else {
messageLabel.Text = "Login failed";
passwordEntry.Text = string.Empty;
theEditor.Text += theResponseObject.status + "\n";
theEditor.Text += theResponseObject.message + "\n";
}
}
}
}我是新来的http客户端,所以任何帮助都将是惊人的!
提前感谢!
发布于 2017-04-24 22:01:38
此服务器的证书无效。您可能正在连接到一个假装为“service.brainstorminstruments.com”的服务器,这可能会使您的机密信息处于危险之中。
在下面的所有项目列表中,没有生成完整的错误,也不知道您正在使用的iOS版本(假设是iOS10),我将假设设备或macOS上的日期/时间是不正确的。
这也可能是由多个问题造成的:
iOS 10中可用的受信任根证书列表
苹果的HTTPS服务器信任评估:
注意:在许多支持不安全密码的领域,您的服务确实失败了ssllabs.com评估,但这不会导致iOS失败。
https://stackoverflow.com/questions/43595512
复制相似问题