コード例 #1
0
ファイル: NetRequest.cs プロジェクト: ycaihua/rhodes
        private String makeClientCookie(HttpWebResponse response)
        {
            String strRes = "";

            if (response.Cookies != null)
            {
                try
                {
                    CookieContainer container = new CookieContainer();
                    container.Add(new Uri(m_strUrl), response.Cookies);
                    strRes = container.GetCookieHeader(new Uri(m_strUrl));
                }catch (Exception exc)
                {
                    LOG.WARNING("CookieContainer failed: " + exc.ToString());
                }
            }

            if (strRes != null && strRes.Length > 0)
            {
                return(strRes);
            }

            for (int i = 0; i < response.Headers.Count; i++)
            {
                String strName  = response.Headers.AllKeys[i];
                String strValue = response.Headers[strName];

                if (strName.equalsIgnoreCase("Set-Cookie"))
                {
                    LOG.INFO("Set-Cookie: " + strValue);

                    int    nSep   = strValue.IndexOf(';');
                    String strVal = strValue;
                    if (nSep > 0)
                    {
                        strVal = strVal.substring(0, nSep);
                    }

                    strRes += strVal;//URI.parseCookie(strVal);
                }
            }

            return(strRes);
        }
コード例 #2
0
ファイル: RhoView.xaml.cs プロジェクト: skflames1000/rhodes
        private void WebBrowser_OnScriptNotify(object sender, NotifyEventArgs e)
        {
            string request = e.Value;

            if (request.startsWith(JS_NOTIFY_CONSOLE_LOG))
            {
                JSLOG.INFO(request.substring(JS_NOTIFY_CONSOLE_LOG.length()).trim());
            }
            else if (request.startsWith(JS_NOTIFY_CONSOLE_INFO))
            {
                JSLOG.INFO(request.substring(JS_NOTIFY_CONSOLE_INFO.length()).trim());
            }
            else if (request.startsWith(JS_NOTIFY_CONSOLE_WARNING))
            {
                JSLOG.WARNING(request.substring(JS_NOTIFY_CONSOLE_WARNING.length()).trim());
            }
            else if (request.startsWith(JS_NOTIFY_CONSOLE_ERROR))
            {
                JSLOG.ERROR(request.substring(JS_NOTIFY_CONSOLE_ERROR.length()).trim());
            }
            else if (request.startsWith(JS_NOTIFY_REQUEST))
            {
                string req = request.substring(JS_NOTIFY_REQUEST.length()).trim();

                IDictionary res = null;
                try
                {
                    res = (IDictionary)fastJSON.RJSONTokener.JsonDecode(req);
                }
                catch (Exception ex)
                {
                    LOG.ERROR("JsonDecode", ex);
                    throw ex;
                }

                if (null != res)
                {
                    string      url         = res["url"].ToString();
                    string      type        = res["type"].ToString().toUpperCase();
                    string      contentType = res["contentType"].ToString();
                    IDictionary headers     = (IDictionary)res["headers"];
                    headers["X-Requested-With"] = "XMLHttpRequest";
                    IDictionary data = (IDictionary)res["data"];

                    string httpUsername = (null == res["usename"]) ? null : res["usename"].ToString();
                    string httpPassword = (null == res["password"]) ? null : res["password"].ToString();
                    string ajaxContext  = data[AJAX_CONTEXT_PARAM].ToString();

                    int tabIdx = RHODESAPP().getTabIndexFor(sender);

                    if (!RHODESAPP().HttpServer.processBrowserRequest(
                            type,
                            new Uri(pathFromUrl(url), UriKind.Relative),
                            headers,
                            data,
                            ajaxContext,
                            tabIdx
                            ))
                    {
                        LOG.ERROR("External requests should be filtered in javascript");
                    }
                }
                else
                {
                    LOG.ERROR("Empty request URI");
                }
            }
        }