2017-04-24 14 views
0

こんにちは私はユーザ名とパスワードを入力してログインボタンをクリックするとログイン画面を持つXamarinフォームアプリケーションを開発しています。 。しかし、私だけで、ログイン失敗したメッセージにXamarinフォームのログインページが私のWebサービスに接続していません

EDITを得ることをやっていないです:

The certificate for this server is invalid. You might be connecting to a server that is pretending to be “service.brainstorminstruments.com” which could put your confidential information at risk.

HERESに私の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> 

EDIT今、私は次のエラーでのiOS上でクラッシュを取得します

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"; 


      } 
     } 


    } 
} 
01:私はHERESに間違ったクラス

の背後にあるコードを使用していました

私はhttpクライアントに新しいので、どんな助けも素晴らしいだろう!

ありがとうございます!以下のすべての項目のリストのうち

+0

あなたが実際にあなたが任意のエラー・コードやメッセージのために戻ってサーバから取得応答を調べたことがありますか?あなたがすべての応答を得ているなら、それはサーバーに接続できたことを意味します。 – Jason

+0

@Jason私は – Phoneswapshop

+0

を持っていません。なぜ、両方のページにサインアップとログインハンドラがありますか?あなたは正しいものを呼んでいると確信していますか? – Jason

答えて

0

The certificate for this server is invalid. You might be connecting to a server that is pretending to be “service.brainstorminstruments.com” which could put your confidential information at risk.

、完全なエラーが発生したり、作業しているどのようなiOSのバージョンを知られることなく、私はに行きます(それがiOS10であると仮定)は、上の日付/時間前提とあなたデバイスまたはmacOSが間違っています。

これは、複数の問題が原因で発生することができます。

  • は、デバイスの日付/時刻間違っている、またはシミュレータ上で実行していることは正しい、あなたのMacOSで使用

  • 日付/時間であれば自己署名証明書が署名された

  • 証明書チェーンの有効なルート証明書がありません。 iOSの10で利用可能な信頼できるルート証明書の

一覧

AppleのHTTPSサーバ信託の評価:

注:セキュリティで保護されていない暗号をサポートするための数多くの分野でサービスがssllabs.comの評価に失敗しても、iOSは失敗しません。

+0

私のウェブブロッカーがサービスURLをブロックしていた一度私は別のネットワーク上でそれを試しても、アプリケーションはもはやクラッシュする、しかし、私はエラーが発生しているユーザー名とパスワードは、これはなぜ今のアイデアは正しくないと言っている?前もって感謝します! – Phoneswapshop

+0

@Phoneswapshopあなたのコードサンプルでは、​​ 'usernameEntry'と' passwordEntry'は 'passwordEntry.Text' *のようなものでなければなりません。実際に' usernameEntry'と 'passwordEntry'という文字列をあなたのサービスに送ります。 – SushiHangover

+0

本当にありがとうございました!!! – Phoneswapshop

関連する問題