Ionic 2与HTTPS服务器通信

时间:2016-10-11 09:53:34

标签: ionic-framework https ionic2

我有一个有效的离子2应用程序(在 2.0.0-beta.4 上运行),它使用 HTTP POST 与我的服务器通信。

/// <summary>
/// Calculate the number of soft line breaks
/// </summary>
private static int GetSplittedLineCount(this XGraphics gfx, string content, XFont font, double maxWidth)
{
    //handy function for creating list of string
    Func<string, IList<string>> listFor = val => new List<string> { val };
    // string.IsNullOrEmpty is too long :p
    Func <string, bool> nOe = str => string.IsNullOrEmpty(str);
    // return a space for an empty string (sIe = Space if Empty)
    Func<string, string> sIe = str => nOe(str) ? " " : str;
    // check if we can fit a text in the maxWidth
    Func<string, string, bool> canFitText = (t1, t2) => gfx.MeasureString($"{(nOe(t1) ? "" : $"{t1} ")}{sIe(t2)}", font).Width <= maxWidth;

    Func<IList<string>, string, IList<string>> appendtoLast =
            (list, val) => list.Take(list.Count - 1)
                               .Concat(listFor($"{(nOe(list.Last()) ? "" : $"{list.Last()} ")}{sIe(val)}"))
                               .ToList();

    var splitted = content.Split(' ');

    var lines = splitted.Aggregate(listFor(""),
            (lfeed, next) => canFitText(lfeed.Last(), next) ? appendtoLast(lfeed, next) : lfeed.Concat(listFor(next)).ToList(),
            list => list.Count());

    return lines;
}

如何将其转换为HTTPS POST, 如果服务器只接受HTTPS POST请求?

如何插入自签名证书?

我能找到的最近的是Node.JS HTTPS API

1 个答案:

答案 0 :(得分:1)

要插入自签名证书,您需要将应用标记为可调试。但是,这将使用户能够查看控制台日志。

要将您的应用标记为可调试,请在清单文件中添加此行android:debuggable="true"

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    <application android:icon="@drawable/icon"
        android:debuggable="true">
      ...
    </application>
</manifest