Exemplo n.º 1
0
        /// <summary>
        /// task function to do the request
        /// </summary>
        /// <param name="URL">target</param>
        /// <param name="input">object to send to</param>
        /// <param name="pCco">identification object</param>
        /// <param name="pTimeout"timeout duration></param>
        /// <returns></returns>
        private responseStruct sendRequestThread(String URL, Object input, ClientConfigObject pCco, int pTimeout)
        {
            if (URL != null)
            {
                try
                {
                    // get the request stream
                    WebRequest request = WebRequest.Create(URL);
                    request.Method  = "POST";
                    request.Timeout = pTimeout;
                    Stream requestStream = request.GetRequestStream();

                    BinaryFormatter formatter = new BinaryFormatter();
                    formatter.Serialize(requestStream, input);
                    requestStream.Close();

                    // response to the request
                    WebResponse  response = request.GetResponse();
                    StreamReader reader   = new StreamReader(response.GetResponseStream());

                    responseStruct re = new responseStruct();
                    re.responseString = reader.ReadToEnd();
                    re.targetclient   = pCco;
                    return(re);
                }
                catch (Exception) { throw; }
            }

            responseStruct rel = new responseStruct();

            rel.responseString = "REQUEST NOT RECIEVED ERROR";
            rel.targetclient   = pCco;
            return(rel);
        }
Exemplo n.º 2
0
        public responseStruct sendSms(string strUsername, string strPassword, string strApiId, string strTo, string strText, string strUrl)
        {
            string concatValue = computeMessageToConcat(strText);
            //todo: validate complete parameters
            responseStruct results = new responseStruct();

            WebClient client = new WebClient();
            // Add a user agent header in case the requested URI contains a query.
            client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
            client.QueryString.Add("user", strUsername);
            client.QueryString.Add("password", strPassword);
            client.QueryString.Add("api_id", strApiId);
            client.QueryString.Add("to", strTo);
            client.QueryString.Add("text", strText);

            client.QueryString.Add("concat", concatValue);
            string baseurl = strUrl;
            //handle http errors
            try
            {
                Stream data = client.OpenRead(baseurl);
                StreamReader reader = new StreamReader(data);
                results.strMessage = reader.ReadToEnd();
                data.Close();
                reader.Close();
            }
            catch (Exception e)
            {
                results.strError = e.Message;
            }


            return results;

        }
Exemplo n.º 3
0
        public responseStruct sendSms(string strUsername, string strPassword, string strApiId, string strTo, string strText, string strUrl)
        {
            string concatValue = computeMessageToConcat(strText);
            //todo: validate complete parameters
            responseStruct results = new responseStruct();

            WebClient client = new WebClient();

            // Add a user agent header in case the requested URI contains a query.
            client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
            client.QueryString.Add("user", strUsername);
            client.QueryString.Add("password", strPassword);
            client.QueryString.Add("api_id", strApiId);
            client.QueryString.Add("to", strTo);
            client.QueryString.Add("text", strText);

            client.QueryString.Add("concat", concatValue);
            string baseurl = strUrl;

            //handle http errors
            try
            {
                Stream       data   = client.OpenRead(baseurl);
                StreamReader reader = new StreamReader(data);
                results.strMessage = reader.ReadToEnd();
                data.Close();
                reader.Close();
            }
            catch (Exception e)
            {
                results.strError = e.Message;
            }


            return(results);
        }