public ServerResponse Post(PostParms parm)
        {
            var response = new ServerResponse();
            var url      = string.Format("{0}{1}", _domain, parm.EndPoint);
            var request  = (HttpWebRequest)WebRequest.Create(url);

            if (parm.TabId > 0)
            {
                request.Headers["TabID"] = parm.TabId.ToString();
            }
            if (parm.TabId > 0)
            {
                request.Headers["ModuleID"] = parm.ModuleId.ToString();
            }
            request.Headers[RqVerifTokenNameNoUndescrores] = _inputFieldVerificationToken;
            request.ContentType     = "text/json";
            request.Method          = "POST";
            request.KeepAlive       = false;
            request.CookieContainer = _sessionCookiesContainer;
            //request.ReadWriteTimeout = 90;

            using (var streamWriter = new StreamWriter(request.GetRequestStream()))
            {
                streamWriter.Write(parm.Content);
                streamWriter.Flush();
                streamWriter.Close();

                var httpResponse = (HttpWebResponse)request.GetResponse();
                using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                {
                    var result = streamReader.ReadToEnd();
                }
            }
            return(response);
        }
示例#2
0
        public ServerResponse Post(PostParms parm)
        {
            var response = new ServerResponse();

            using (var client = GetUploadContentClient())
            {
                var rqHeaders = client.DefaultRequestHeaders;
                rqHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                rqHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/html", 0.5d));
                rqHeaders.Add("X-Requested-With", "XMLHttpRequest");

                if (parm.TabId > 0)
                {
                    rqHeaders.Add("TabID", parm.TabId.ToString());
                }
                if (parm.TabId > 0)
                {
                    rqHeaders.Add("ModuleID", parm.ModuleId.ToString());
                }

                var url = string.Format("{0}{1}", _domain, parm.EndPoint);
                var uri = new Uri(url);

                var result = client.PostAsJsonAsync(uri.ToString(), parm.Content).Result;
                result.EnsureSuccessStatusCode();

                //return new HttpResponseMessage { StatusCode = HttpStatusCode.Accepted };
            }

            return(response);
        }
示例#3
0
        private void gvMembers_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            //make sure click not on header and column is type of ButtonColumn
            if (e.RowIndex >= 0 && ((DataGridView)sender).Columns[e.ColumnIndex].GetType() == typeof(DataGridViewButtonColumn))
            {
                 //TODO - Execute Code Here
                var row = ((DataGridView) sender).Rows[e.RowIndex];
                var friendStatus = (RelationshipStatus)row.Cells["FriendStatus"].Value;
                var targetUserName = row.Cells["UserName"].Value;
                var targetFriendId = row.Cells["MemberId"].Value;

                var parm = new PostParms
                               {
                                   EndPoint = "DesktopModules/MemberDirectory/API/MemberDirectory/AddFriend",
                                   Content = JsonConvert.SerializeObject(new FriendDto { FriendId = Convert.ToInt32(targetFriendId) }),
                                   TabId = 96,
                                   ModuleId = 484
                               };

                var response = DnnWebApiClientController.Instance.Post(parm);

            }
        }
        public ServerResponse Post(PostParms parm)
        {
            var response = new ServerResponse();
            var url = string.Format("{0}{1}", _domain, parm.EndPoint);
            var request = (HttpWebRequest)WebRequest.Create(url);
            if (parm.TabId > 0) request.Headers["TabID"] = parm.TabId.ToString();
            if (parm.TabId > 0) request.Headers["ModuleID"] = parm.ModuleId.ToString();
            request.Headers[RqVerifTokenNameNoUndescrores] = _inputFieldVerificationToken;
            request.ContentType = "text/json";
            request.Method = "POST";
            request.KeepAlive = false;
            request.CookieContainer = _sessionCookiesContainer;
            //request.ReadWriteTimeout = 90;

            using (var streamWriter = new StreamWriter(request.GetRequestStream()))
            {
                streamWriter.Write(parm.Content);
                streamWriter.Flush();
                streamWriter.Close();

                var httpResponse = (HttpWebResponse) request.GetResponse();
                using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                {
                    var result = streamReader.ReadToEnd();
                }
            }
            return response;
        }
        public ServerResponse Post(PostParms parm)
        {
            var response = new ServerResponse();

            using (var client = GetUploadContentClient())
            {
                var rqHeaders = client.DefaultRequestHeaders;
                rqHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                rqHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/html", 0.5d));
                rqHeaders.Add("X-Requested-With", "XMLHttpRequest");

                if (parm.TabId > 0) rqHeaders.Add("TabID", parm.TabId.ToString());
                if (parm.TabId > 0) rqHeaders.Add("ModuleID", parm.ModuleId.ToString());

                var url = string.Format("{0}{1}", _domain, parm.EndPoint);
                var uri = new Uri(url);

                var result = client.PostAsJsonAsync(uri.ToString(), parm.Content).Result;
                result.EnsureSuccessStatusCode();

                //return new HttpResponseMessage { StatusCode = HttpStatusCode.Accepted };
            }

            return response;
        }