从Windows Phone访问HTTPS服务器时出现问题

时间:2013-12-03 19:35:15

标签: windows windows-phone-7 windows-phone-8

我正试图从Windows Phone设备/ Windows Phone模拟器中点击HTTPS服务器。但是请求没有到达服务器。

服务器已安装SSL证书,在Windows Phone上我手动安装了证书。但后来也无法继续。

请求是HTTPS。当我们发出HTTP请求时,手机正在点击服务器并且响应即将到来,但对于HTTPS来说,它之间是失败的。

请让我知道解决方案。

提前致谢。


以下是制作HTTP Web请求的用法: -

公共类ConnectionHandler     {         ///         ///保持连接状态。         ///         public static bool done = false;

    /// <summary>
    /// Holds the status of the connection
    /// Backkey press handling OTRS Ticket#1000543 [25 Jun 13]
    /// </summary>
    public static bool initiated = false;

    /// <summary>
    /// Holds the response xml from the server
    /// </summary>
    public static string strResponseXML
    {
        get;
        set;
    }

    /// <summary>
    /// Holds the parameters related to the request
    /// </summary>
    public static string strRequestParams
    {
        get;
        set;
    }

    /// <summary>
    /// Holds the server url
    /// </summary>
    public static string strUrl
    {
        get;
        set;
    }

    /// <summary>
    /// Holds the session cookie
    /// </summary>
    public static string cookie
    {
        get;
        set;
    }

    /// <summary>
    /// Holds the page name parameter
    /// </summary>
    public static string pageName
    {
        get;
        set;
    }

    /// <summary>
    /// The method <code>connectToServer</code> sends the asynchronous request to the server.
    /// </summary>
    public static void connectToServer()
    {
        // Create the web request object 
        done = false;
        initiated = true;
        HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(strUrl);
        PageRequestHandler.CurrentPageURL = strUrl + "?" + strRequestParams;
        System.Diagnostics.Debug.WriteLine(System.DateTime.Now + ">>>fullpageRequest>>>" + PageRequestHandler.CurrentPageURL);
        System.Diagnostics.Debug.WriteLine(System.DateTime.Now + ">>>PostData>>>" + getParam());
        System.Diagnostics.Debug.WriteLine(System.DateTime.Now + ">>>PostData>>>" + strRequestParams);
        webRequest.Method = "POST";

        webRequest.ContentType = "application/x-www-form-urlencoded";

        //webRequest.Headers["Cookie"] = cookie;
        // Start the request 
        webRequest.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback), webRequest);

        while (!done)
        {
            Thread.Sleep(100);
        }
    }

    /// <summary>
    /// The method <code>GetRequestStreamCallback</code> sends the parameters to the request and start getting the response asynchronously.
    /// </summary>
    /// <param name="asynchronousResult"></param>
    static void GetRequestStreamCallback(IAsyncResult asynchronousResult)
    {

        HttpWebRequest webRequest = (HttpWebRequest)asynchronousResult.AsyncState;

        //End the stream request operation 

        Stream postStream = webRequest.EndGetRequestStream(asynchronousResult);

        // Add the request parameters to the web request 
        //strRequestParams = "Channel=WP7&screenWidth=480&screenHeight=700&page=CheckBoxHome";

        byte[] byteArray = Encoding.UTF8.GetBytes(getParam());

        postStream.Write(byteArray, 0, byteArray.Length);

        postStream.Close();

        // Start the web request 

        webRequest.BeginGetResponse(new AsyncCallback(GetResponseCallback), webRequest);

    }

    /// <summary>
    /// The method <code>GetResponseCallback</code> receives the response asynchronously and store the response xml in strResponseXML.
    /// </summary>
    /// <param name="asynchronousResult"></param>
    static void GetResponseCallback(IAsyncResult asynchronousResult)
    {
        StreamReader streamReader = null;
        try
        {
            strResponseXML = "";
            HttpWebRequest webRequest = (HttpWebRequest)asynchronousResult.AsyncState;

            HttpWebResponse response;

            // End the get response operation 

            response = (HttpWebResponse)webRequest.EndGetResponse(asynchronousResult);

            //cookie=response.Cookies["Set-Cookie"].ToString();

            Stream streamResponse = response.GetResponseStream();

            streamReader = new StreamReader(streamResponse);

            strResponseXML = streamReader.ReadToEnd();

            streamResponse.Close();

            streamReader.Close();

            response.Close();
            System.Diagnostics.Debug.WriteLine(System.DateTime.Now + ">>>Response xml from server>>>\n" + strResponseXML);
        }

        catch (WebException e)
        {
            // Error treatment 
            // ... 
            string ex = e.Message;

        }
        done = true;
        initiated = false;
        //Deployment.Current.Dispatcher.BeginInvoke(new Action(() =>
        //{
        //    strResponseXML = streamReader.ReadToEnd();
        //}));
        //streamReader.Close();
    }

   static  string GetEncodedValue(string value)
    {
        if (Convert.ToBoolean(ConfigManager.URL_ENCODE))
        {
            return HttpUtility.UrlEncode(value);
        }
        else
            return value;
    }
   static string getParam()
    {
        string param = "";
        if (ConnectionHandler.strRequestParams.Contains("&"))
        {
            string[] paramArray = strRequestParams.Split('&');
            foreach (string keyValue in paramArray)
            {
                if (keyValue.Contains("="))
                {
                    string[] keys = keyValue.Split('=');
                    param = param+keys[0]+"="+GetEncodedValue(keys[1])+"&";
                }

            }
        }
        else
            param = ConnectionHandler.strRequestParams;
        return param;

    }

}

从HTTP Web服务器下载证书并手动安装在手机上。

Pease帮助我解决问题。

由于

0 个答案:

没有答案