Beispiel #1
0
 public string[] getJobStaties()
 {
     String[] staties = new String[jobids.Length];
     for (int i = 0; i < jobids.Length; i++)
     {
         CodeScales.Http.HttpClient httpClient = new CodeScales.Http.HttpClient();
         HttpGet      httpGet  = new HttpGet(new Uri(url + "/api/jobs/" + jobids[i]));
         HttpResponse response = httpClient.Execute(httpGet);
         HttpEntity   entity   = response.Entity;
         String       results  = EntityUtils.ToString(entity);
         if (debug)
         {
             Console.WriteLine("getJobStaties gets:" + response.ResponseCode);
             Console.WriteLine("getJobStaties    :" + results);
         }
         String status = jsonGetValue(results, "status");
         if (debug)
         {
             if (jobids[i] != "")
             {
                 Console.WriteLine(jobids[i] + "    " + status);
             }
         }
         staties[i] = status;
     }
     return(staties);
 }
        public void HttpPostWithFilesAndParameters()
        {
            // this method sends an empty file (or no file :)
            HttpClient client = new HttpClient();
            HttpPost postMethod = new HttpPost(new Uri(Constants.HTTP_MULTIPART_POST_200));

            MultipartEntity multipartEntity = new MultipartEntity();
            StringBody stringBody1 = new StringBody(Encoding.ASCII, "param1", "value1");
            multipartEntity.AddBody(stringBody1);
            StringBody stringBody2 = new StringBody(Encoding.ASCII, "param2", "!#$^&*((<>");
            multipartEntity.AddBody(stringBody2);
            FileBody fileBody1 = new FileBody("photo", "me.file", null);
            multipartEntity.AddBody(fileBody1);
            postMethod.Entity = multipartEntity;
            HttpResponse response = client.Execute(postMethod);

            Assert.AreEqual(200, response.ResponseCode);
            string responseString = EntityUtils.ToString(response.Entity);
            MessageData md = new MessageData();
            md.PostParameters.Add(new NameValuePair("param1", "value1"));
            md.PostParameters.Add(new NameValuePair("param2", "!#$^&*((<>"));
            md.Files.Add(new NameValuePair("me.file", "0"));
            Assert.AreEqual(md.ToString(), responseString);
            Assert.AreEqual(Constants.HTTP_MULTIPART_POST_200, response.RequestUri.AbsoluteUri);
            Console.Write(responseString);
        }
Beispiel #3
0
        public CalibrationData getCalibration(string jobid)
        {
            StringBuilder builder = new StringBuilder();
            String        result  = "";

            CodeScales.Http.HttpClient httpClient = new CodeScales.Http.HttpClient();
            HttpGet      httpGet  = new HttpGet(new Uri(url + "/api/jobs/" + jobid + "/calibration"));
            HttpResponse response = httpClient.Execute(httpGet);
            HttpEntity   entity   = response.Entity;
            String       content  = EntityUtils.ToString(entity);

            if (debug)
            {
                Console.WriteLine("getCalibration gets: " + content);
            }
            String parity      = jsonGetValue(content, "parity");
            String orientation = jsonGetValue(content, "orientation");
            String pixscale    = jsonGetValue(content, "pixscale");
            String radius      = jsonGetValue(content, "radius");
            String radecimal   = jsonGetValue(content, "ra");
            String decdecimal  = jsonGetValue(content, "dec");

            CalibrationData res = new CalibrationData();

            res.parity      = Double.Parse(parity);
            res.orientation = Double.Parse(orientation);
            res.pixscale    = Double.Parse(pixscale);
            res.radius      = Double.Parse(radius);
            res.ra          = Double.Parse(radecimal);
            res.dec         = Double.Parse(decdecimal);

            return(res);
        }
Beispiel #4
0
        public static void SendWelcomeMail(string userName,string email)
        {
            HttpClient client = new HttpClient();
            HttpPost postMethod = new HttpPost(new Uri("http://sendcloud.sohu.com/webapi/mail.send_template.json"));
            MultipartEntity multipartEntity = new MultipartEntity();
            postMethod.Entity = multipartEntity;
            multipartEntity.AddBody(new StringBody(Encoding.UTF8, "template_invoke_name", "superjokes_register"));
            multipartEntity.AddBody(new StringBody(Encoding.UTF8, "substitution_vars", "{\"to\": [\"" + email + "\"], \"sub\" : { \"%username%\" : [\"" + userName + "\"]}}"));
            multipartEntity.AddBody(new StringBody(Encoding.UTF8, "api_user", "superjokes_cn"));
            multipartEntity.AddBody(new StringBody(Encoding.UTF8, "api_key", AppConfig.SendCloudKey));
            multipartEntity.AddBody(new StringBody(Encoding.UTF8, "from", "*****@*****.**"));
            multipartEntity.AddBody(new StringBody(Encoding.UTF8, "fromname", "超级冷笑话"));
            multipartEntity.AddBody(new StringBody(Encoding.UTF8, "subject", "超级冷笑话注册邮件"));
            CodeScales.Http.Methods.HttpResponse response = client.Execute(postMethod);

            var repCode = response.ResponseCode;
            var repResult = EntityUtils.ToString(response.Entity);
            //LogHelper.Info("reg:" + email + repResult + AppConfig.SendCloudKey);

            //Console.WriteLine("Response Code: " + response.ResponseCode);
            //Console.WriteLine("Response Content: " + EntityUtils.ToString(response.Entity));

            //Response.Write("Response Code: " + response.ResponseCode);
            //Response.Write("<br/>");
            //Response.Write("Response Content: " + EntityUtils.ToString(response.Entity));
        }
Beispiel #5
0
        public void HttpGetWithCookies()
        {
            // with SetMaxRedirects
            // make sure we are not redirected
            HttpClient client = new HttpClient();
            client.MaxRedirects = 0;
            HttpGet getMethod = new HttpGet(new Uri(Constants.HTTP_GET_200_WITH_SET_COOKIES));
            getMethod.Parameters.Add("cookie1", "value1");
            getMethod.Parameters.Add("cookie2", "value2");
            HttpResponse response = client.Execute(getMethod);

            Assert.AreEqual(200, response.ResponseCode);
            Assert.AreEqual(Constants.HTTP_GET_200_WITH_SET_COOKIES, response.RequestUri.AbsoluteUri);

            getMethod = new HttpGet(new Uri(Constants.HTTP_GET_200));
            response = client.Execute(getMethod);

            Assert.AreEqual(200, response.ResponseCode);
            Assert.AreEqual(Constants.HTTP_GET_200, response.RequestUri.AbsoluteUri);

            // assert the cookies
            MessageData md = new MessageData();
            md.Cookies.Add(new NameValuePair("cookie1", "value1"));
            md.Cookies.Add(new NameValuePair("cookie2", "value2"));
            string responseString = EntityUtils.ToString(response.Entity);
            Assert.AreEqual(md.ToString(), responseString);
            Console.Write(responseString);            
        }
        public static void DoGet()
        {
            HttpClient httpClient = new HttpClient();
            HttpGet httpGet = new HttpGet(new Uri("http://www.codescales.com"));
            HttpResponse httpResponse = httpClient.Execute(httpGet);

            Console.WriteLine("Response Code: " + httpResponse.ResponseCode);
            Console.WriteLine("Response Content: " + EntityUtils.ToString(httpResponse.Entity));
        }
        public static void DoGetWithProxy()
        {
            HttpClient httpClient = new HttpClient();
            httpClient.Proxy = new Uri("http://localhost:8888/"); // default address of fiddler
            HttpGet httpGet = new HttpGet(new Uri("http://www.codescales.com"));
            HttpResponse httpResponse = httpClient.Execute(httpGet);

            Console.WriteLine("Response Code: " + httpResponse.ResponseCode);
            Console.WriteLine("Response Content: " + EntityUtils.ToString(httpResponse.Entity));
        }
        public static void DoGetWithRedirects()
        {
            HttpClient httpClient = new HttpClient();
            httpClient.MaxRedirects = 0;
            HttpGet httpGet = new HttpGet(new Uri("http://www.codescales.com/home"));
            HttpResponse httpResponse = httpClient.Execute(httpGet);

            Console.WriteLine("Response Code: " + httpResponse.ResponseCode);
            Console.WriteLine("Response Code: " + httpResponse.Location);
            Console.WriteLine("Response Content: " + EntityUtils.ToString(httpResponse.Entity));
        }
        public void HttpGet()
        {
            HttpClient client = new HttpClient();
            HttpGet getMethod = new HttpGet(new Uri(Constants.HTTP_GET_200));
            HttpResponse response = client.Execute(getMethod);

            Assert.AreEqual(200, response.ResponseCode);
            string responseString = EntityUtils.ToString(response.Entity);
            Assert.AreEqual(MessageData.Empty.ToString(), responseString);
            Assert.AreEqual(Constants.HTTP_GET_200, response.RequestUri.AbsoluteUri);
            Console.Write(responseString);
        }
        public void HttpGetWithRedirect2()
        {
            // with SetMaxRedirects
            // make sure we were redirected
            HttpClient client = new HttpClient();
            client.MaxRedirects = 1;
            HttpGet getMethod = new HttpGet(new Uri(Constants.HTTP_GET_302));
            HttpResponse response = client.Execute(getMethod);

            Assert.AreEqual(200, response.ResponseCode);
            Assert.AreEqual(Constants.HTTP_REDIRECT_TARGET_1, response.RequestUri.AbsoluteUri);
            string responseString = EntityUtils.ToString(response.Entity);
            Console.Write(responseString);
        }
        public void HttpGetWithChunkedResponse2()
        {
            // we use codescales.com that is hosted by google
            // the google server always uses chunked transfer-encoding

            HttpClient client = new HttpClient();
            HttpGet getMethod = new HttpGet(new Uri("http://forums.photographyreview.com/showthread.php?t=68825"));
            HttpResponse response = client.Execute(getMethod);

            Assert.AreEqual(200, response.ResponseCode);
            string responseString = EntityUtils.ToString(response.Entity);
            Assert.AreEqual("http://forums.photographyreview.com/showthread.php?t=68825", response.RequestUri.AbsoluteUri);
            Console.Write(responseString);
        }
        public void HttpGetWithChunkedResponse()
        {
            // we use codescales.com that is hosted by google
            // the google server always uses chunked transfer-encoding

            HttpClient client = new HttpClient();
            HttpGet getMethod = new HttpGet(new Uri(Constants.HTTP_GET_200_CODESCALES_COM));
            HttpResponse response = client.Execute(getMethod);

            Assert.AreEqual(200, response.ResponseCode);
            string responseString = EntityUtils.ToString(response.Entity);
            Assert.AreEqual(Constants.HTTP_GET_200_CODESCALES_COM, response.RequestUri.AbsoluteUri);
            Console.Write(responseString);
        }
        public static void DoGetWithRedirects2()
        {
            HttpClient httpClient = new HttpClient();
            HttpGet httpGet = new HttpGet(new Uri("http://www.codescales.com/home"));

            HttpBehavior httpBehavior = new HttpBehavior();
            httpBehavior.AddStep(301, "http://www.codescales.com");
            httpBehavior.AddStep(200);

            HttpResponse httpResponse = httpClient.Execute(httpGet, httpBehavior);

            Console.WriteLine("Response Code: " + httpResponse.ResponseCode);
            Console.WriteLine("Response Code: " + httpResponse.Location);
            Console.WriteLine("Response Content: " + EntityUtils.ToString(httpResponse.Entity));
        }
        public void HttpGetWithRedirect3()
        {
            // this time with HTTPBehavior
            // make sure we were redirected and no exception is thrown
            HttpClient client = new HttpClient();
            HttpBehavior httpBehavior = new HttpBehavior();
            httpBehavior.AddStep(302, Constants.HTTP_REDIRECT_TARGET_1);
            httpBehavior.AddStep(200);
            HttpGet getMethod = new HttpGet(new Uri(Constants.HTTP_GET_302));
            HttpResponse response = client.Execute(getMethod, httpBehavior);

            Assert.AreEqual(200, response.ResponseCode);
            Assert.AreEqual(Constants.HTTP_REDIRECT_TARGET_1, response.RequestUri.AbsoluteUri);
            string responseString = EntityUtils.ToString(response.Entity);
            Console.Write(responseString);
        }
Beispiel #15
0
        public static void DoPost()
        {
            HttpClient client = new HttpClient();
            HttpPost postMethod = new HttpPost(new Uri("http://www.w3schools.com/asp/demo_simpleform.asp"));

            List<NameValuePair> nameValuePairList = new List<NameValuePair>();
            nameValuePairList.Add(new NameValuePair("fname", "brian"));
            
            UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nameValuePairList, Encoding.UTF8);
            postMethod.Entity = formEntity;
            
            HttpResponse response = client.Execute(postMethod);

            Console.WriteLine("Response Code: " + response.ResponseCode);
            Console.WriteLine("Response Content: " + EntityUtils.ToString(response.Entity));
        }
Beispiel #16
0
        public void HttpGetWithParameters()
        {
            HttpClient client = new HttpClient();
            HttpGet getMethod = new HttpGet(new Uri(Constants.HTTP_GET_200));
            getMethod.Parameters.Add("test", "1 and text");
            getMethod.Parameters.Add("test2", "2 and text <> &&");
            HttpResponse response = client.Execute(getMethod);

            Assert.AreEqual(200, response.ResponseCode);
            Assert.AreEqual(Constants.HTTP_GET_200, response.RequestUri.AbsoluteUri);
            // assert the parameters
            MessageData md = new MessageData();
            md.QueryParameters.Add(new NameValuePair("test", "1 and text"));
            md.QueryParameters.Add(new NameValuePair("test2", "2 and text <> &&"));
            string responseString = EntityUtils.ToString(response.Entity);
            Assert.AreEqual(md.ToString(), responseString);
            Console.Write(responseString);
        }
Beispiel #17
0
        public static void VerifyNotice(string userName,string email,string jokeTitle,string jokeurl)
        {
            HttpClient client = new HttpClient();
            HttpPost postMethod = new HttpPost(new Uri("http://sendcloud.sohu.com/webapi/mail.send_template.json"));
            MultipartEntity multipartEntity = new MultipartEntity();
            postMethod.Entity = multipartEntity;
            multipartEntity.AddBody(new StringBody(Encoding.UTF8, "template_invoke_name", "superjokes_verifynotice"));
            multipartEntity.AddBody(new StringBody(Encoding.UTF8, "substitution_vars", "{\"to\": [\"" + email + "\"], \"sub\" : { \"%username%\" : [\"" + userName + "\"],\"%joketitle%\":[\"" + jokeTitle + "\"],\"%jokeurl%\":[\"" + jokeurl + "\"]}}"));
            multipartEntity.AddBody(new StringBody(Encoding.UTF8, "api_user", "superjokes_cn"));
            multipartEntity.AddBody(new StringBody(Encoding.UTF8, "api_key", AppConfig.SendCloudKey));
            multipartEntity.AddBody(new StringBody(Encoding.UTF8, "from", "*****@*****.**"));
            multipartEntity.AddBody(new StringBody(Encoding.UTF8, "fromname", "超级冷笑话"));
            multipartEntity.AddBody(new StringBody(Encoding.UTF8, "subject", "超级冷笑话审核通知"));
            CodeScales.Http.Methods.HttpResponse response = client.Execute(postMethod);

            var repCode = response.ResponseCode;
            var repResult = EntityUtils.ToString(response.Entity);
            //LogHelper.Info("verify:" + email + repResult + AppConfig.SendCloudKey);
        }
        public void HttpPost()
        {
            HttpClient client = new HttpClient();
            HttpPost postMethod = new HttpPost(new Uri(Constants.HTTP_POST_200));
            List<NameValuePair> nameValuePairList = new List<NameValuePair>();
            nameValuePairList.Add(new NameValuePair("param1","value1"));
            nameValuePairList.Add(new NameValuePair("param2","!#$^&*((<>"));
            UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nameValuePairList, Encoding.UTF8);
            postMethod.Entity = formEntity;
            HttpResponse response = client.Execute(postMethod);

            Assert.AreEqual(200, response.ResponseCode);
            string responseString = EntityUtils.ToString(response.Entity);
            MessageData md = new MessageData();
            md.PostParameters.Add(new NameValuePair("param1", "value1"));
            md.PostParameters.Add(new NameValuePair("param2", "!#$^&*((<>"));
            Assert.AreEqual(md.ToString(), responseString);
            Assert.AreEqual(Constants.HTTP_POST_200, response.RequestUri.AbsoluteUri);
            Console.Write(responseString);
        }
Beispiel #19
0
        public string postFile(string session, string fileName)
        {
            int    GOOD_RETURN_CODE = 200;
            string subIdLocal       = "";

            FileStream imageFile = File.OpenRead(fileName);

            CodeScales.Http.HttpClient httpClient = new CodeScales.Http.HttpClient();
            HttpPost httpPost = new HttpPost(new Uri(url + "/api/upload/"));


            JsonObject      jsonObject = getUploadJSON(session);
            MultipartEntity reqEntity  = new MultipartEntity();

            StringBody stringBody = new StringBody(Encoding.UTF8, "request-json", jsonObject.ToString());

            reqEntity.AddBody(stringBody);
            FileInfo fileInfo = new FileInfo(fileName);
            FileBody fileBody = new FileBody("file", fileName, fileInfo);

            reqEntity.AddBody(fileBody);

            httpPost.Entity = reqEntity;
            HttpResponse response = httpClient.Execute(httpPost);

            String result = "";

            int respCode = response.ResponseCode;

            if (respCode == GOOD_RETURN_CODE)
            {
                HttpEntity entity  = response.Entity;
                String     content = EntityUtils.ToString(entity);
                string     success = jsonGetValue(content, "status");
                subIdLocal = jsonGetValue(content, "subid");
                string hash = jsonGetValue(content, "hash");
            }

            return(subIdLocal);
        }
Beispiel #20
0
        public void HttpPostWithParameters2()
        {
            HttpClient client = new HttpClient();

            // first request - to get cookies
            HttpGet getMethod = new HttpGet(new Uri(Constants.HTTP_POST_W3SCHOOLS));
            HttpResponse response = client.Execute(getMethod);
            Assert.AreEqual(200, response.ResponseCode);

            // second request - to send form data
            HttpPost postMethod = new HttpPost(new Uri(Constants.HTTP_POST_W3SCHOOLS));
            List<NameValuePair> nameValuePairList = new List<NameValuePair>();
            nameValuePairList.Add(new NameValuePair("fname", "user 1"));
            UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nameValuePairList, Encoding.UTF8);
            postMethod.Entity = formEntity;
            response = client.Execute(postMethod);

            Assert.AreEqual(200, response.ResponseCode);
            string responseString = EntityUtils.ToString(response.Entity);
            Assert.IsTrue(responseString.Contains("Hello user 1!"));

        }
        public void HttpGetWithRedirect7()
        {
            // this time with HTTPBehavior
            // make sure we get only the first response
            // and do not make the second call
            HttpClient client = new HttpClient();
            HttpBehavior httpBehavior = new HttpBehavior();
            httpBehavior.AddStep(302, Constants.HTTP_REDIRECT_TARGET_1);
            HttpGet getMethod = new HttpGet(new Uri(Constants.HTTP_GET_302));
            HttpResponse response = client.Execute(getMethod, httpBehavior);

            Assert.AreEqual(302, response.ResponseCode);
            Assert.AreEqual(Constants.HTTP_REDIRECT_TARGET_1, response.Location);
        }
        public void HttpPostWithFilesAndParameters3()
        {
            // this method sends a file and checks for the number of bytes recieved
            HttpClient client = new HttpClient();
            string url = "http://www.fiddler2.com/sandbox/FileForm.asp";
            HttpPost postMethod = new HttpPost(new Uri(url));

            MultipartEntity multipartEntity = new MultipartEntity();
            postMethod.Entity = multipartEntity;

            string fileName = "small-text.txt";

            StringBody stringBody1 = new StringBody(Encoding.ASCII, "1", "1_");
            multipartEntity.AddBody(stringBody1);

            FileInfo fi = ResourceManager.GetResourceFileInfo(fileName);
            FileBody fileBody1 = new FileBody("fileentry", fileName, fi, "text/plain");
            multipartEntity.AddBody(fileBody1);

            StringBody stringBody2 = new StringBody(Encoding.ASCII, "_charset_", "windows-1252");
            multipartEntity.AddBody(stringBody2);

            HttpResponse response = client.Execute(postMethod);

            Assert.AreEqual(200, response.ResponseCode);
            string responseString = EntityUtils.ToString(response.Entity);
            Assert.AreEqual(url, response.RequestUri.AbsoluteUri);
            Console.Write(responseString);
        }
        public void HttpPostWithFilesAndParameters2()
        {
            // this method sends a file and checks for the number of bytes recieved
            HttpClient client = new HttpClient();
            HttpPost postMethod = new HttpPost(new Uri(Constants.HTTP_MULTIPART_POST_200));

            MultipartEntity multipartEntity = new MultipartEntity();

            string fileName = "big-text.txt";

            FileInfo fi = ResourceManager.GetResourceFileInfo(fileName);
            FileBody fileBody1 = new FileBody("file", fileName, fi, "text/plain");

            multipartEntity.AddBody(fileBody1);
            postMethod.Entity = multipartEntity;

            StringBody stringBody1 = new StringBody(Encoding.ASCII, "param1", "value1");
            multipartEntity.AddBody(stringBody1);
            StringBody stringBody2 = new StringBody(Encoding.ASCII, "param2", "!#$^&*((<>");
            multipartEntity.AddBody(stringBody2);

            HttpResponse response = client.Execute(postMethod);

            Assert.AreEqual(200, response.ResponseCode);
            string responseString = EntityUtils.ToString(response.Entity);
            MessageData md = new MessageData();
            md.PostParameters.Add(new NameValuePair("param1", "value1"));
            md.PostParameters.Add(new NameValuePair("param2", "!#$^&*((<>"));
            md.Files.Add(new NameValuePair(fileName, fi.Length.ToString()));
            Assert.AreEqual(md.ToString(), responseString);
            Assert.AreEqual(Constants.HTTP_MULTIPART_POST_200, response.RequestUri.AbsoluteUri);
            Console.Write(responseString);
        }
Beispiel #24
0
        internal HttpClient InitializeTransport(out MultipartEntity multipartEntity, out HttpPost postMethod)
        {
            var client = new HttpClient();
            postMethod = new HttpPost(new Uri(_restEndpoint));

            multipartEntity = new MultipartEntity();
            postMethod.Entity = multipartEntity;
            return client;
        }
        public void HttpGetWithRedirect4()
        {
            // this time with HTTPBehavior
            // here both response code and location are wrong
            // make sure an exception is thrown

            HttpClient client = new HttpClient();
            HttpBehavior httpBehavior = new HttpBehavior();
            httpBehavior.AddStep(200);
            HttpGet getMethod = new HttpGet(new Uri(Constants.HTTP_GET_302));
            HttpResponse response = client.Execute(getMethod, httpBehavior);
        }
Beispiel #26
0
        public string[] getJobids(String subID)
        {
            StringBuilder builder = new StringBuilder();
            String        results = "";

            CodeScales.Http.HttpClient httpClient = new CodeScales.Http.HttpClient();
            HttpGet      httpget  = new HttpGet(new Uri(url + "/api/submissions/" + subID));
            HttpResponse response = httpClient.Execute(httpget);
            HttpEntity   entity   = response.Entity;

            results = EntityUtils.ToString(entity);
            if (debug)
            {
                Console.WriteLine("getJobsID gets:" + response.ResponseCode);
                Console.WriteLine("getJobsID     :" + results);
            }



            String jobs = jsonGetValue(results, "jobs");

            jobs = jobs.Replace("[", "");
            jobs = jobs.Replace("]", "");

            if (debug)
            {
                Console.WriteLine("Jobs: " + jobs);
            }

            char[]   separator   = { ',' };
            string[] jobidsLocal = jobs.Split(separator);

            if (debug)
            {
                if (jobidsLocal.Length >= 1)
                {
                    Console.WriteLine("Job IDs:");
                    for (int i = 0; i < jobidsLocal.Length; i++)
                    {
                        Console.WriteLine(jobidsLocal[i]);
                    }
                }
            }
            userid = jsonGetValue(results, "user");
            if (debug)
            {
                Console.WriteLine("\nUserID: " + userid);
            }

            String user_imageslocal = jsonGetValue(results, "user_images");

            user_imageslocal = user_imageslocal.Replace("[", "");
            user_imageslocal = user_imageslocal.Replace("]", "");
            if (debug)
            {
                Console.WriteLine("User_images line: " + user_imageslocal);
            }
            user_images = user_imageslocal.Split(separator);
            if (debug)
            {
                if (user_images.Length >= 1)
                {
                    Console.WriteLine("User images:");
                    for (int i = 0; i < user_images.Length; i++)
                    {
                        Console.WriteLine(user_images[i]);
                    }
                }
            }

            return(jobidsLocal);
        }
Beispiel #27
0
        public static string SendEmailByList(SendCloud sc)
        {
            try
            {
                HttpClient client = new HttpClient();
                HttpPost postMethod = new HttpPost(new Uri("http://sendcloud.sohu.com/webapi/mail.send_template.json"));

                MultipartEntity multipartEntity = new MultipartEntity();
                postMethod.Entity = multipartEntity;

                multipartEntity.AddBody(new StringBody(Encoding.UTF8, "api_user", sc.API_User));
                multipartEntity.AddBody(new StringBody(Encoding.UTF8, "api_key", sc.API_Key));
                multipartEntity.AddBody(new StringBody(Encoding.UTF8, "from", sc.From));
                multipartEntity.AddBody(new StringBody(Encoding.UTF8, "fromname", sc.FromName));
                multipartEntity.AddBody(new StringBody(Encoding.UTF8, "subject", string.Join(" ", sc.listSubject.ToArray())));
                multipartEntity.AddBody(new StringBody(Encoding.UTF8, "template_invoke_name", sc.Template));
                multipartEntity.AddBody(new StringBody(Encoding.UTF8, "use_maillist", "true"));
                multipartEntity.AddBody(new StringBody(Encoding.UTF8, "to", sc.To));
                multipartEntity.AddBody(new StringBody(Encoding.UTF8, "label", sc.Label));

                HttpResponse response = client.Execute(postMethod);

                return response.ResponseCode.ToString();
            }
            catch (Exception e)
            {
                return e.ToString();
            }
        }
Beispiel #28
0
        public static bool SendEmail(SendCloud sc)
        {
            bool result = false;
            int iPageSize = 100;
            int iPageCount = sc.listVar.Count / iPageSize + (sc.listVar.Count % iPageSize == 0 ? 0 : 1);
            for (int i = 0; i < iPageCount; i++)
            {
                try
                {
                    string sVar = GetVarJson(sc.listVar.GetRange(i * iPageSize, i == iPageCount - 1 ? sc.listVar.Count - iPageSize * i : iPageSize));
                    sVar = sVar.Replace("\r", "").Replace("\n", "");

                    HttpClient client = new HttpClient();
                    HttpPost postMethod = new HttpPost(new Uri("http://sendcloud.sohu.com/webapi/mail.send_template.json"));

                    MultipartEntity multipartEntity = new MultipartEntity();
                    postMethod.Entity = multipartEntity;

                    multipartEntity.AddBody(new StringBody(Encoding.UTF8, "api_user", sc.API_User));
                    multipartEntity.AddBody(new StringBody(Encoding.UTF8, "api_key", sc.API_Key));
                    multipartEntity.AddBody(new StringBody(Encoding.UTF8, "from", sc.From));
                    multipartEntity.AddBody(new StringBody(Encoding.UTF8, "fromname", sc.FromName));
                    multipartEntity.AddBody(new StringBody(Encoding.UTF8, "subject", string.Join(" ", sc.listSubject.ToArray())));
                    multipartEntity.AddBody(new StringBody(Encoding.UTF8, "template_invoke_name", sc.Template));
                    multipartEntity.AddBody(new StringBody(Encoding.UTF8, "label", sc.Label));
                    multipartEntity.AddBody(new StringBody(Encoding.UTF8, "substitution_vars", sVar));

                    HttpResponse response = client.Execute(postMethod);
                    //result += sVar + Environment.NewLine;

                    if (response.ResponseCode == 200)
                        result = true;
                    //{
                    //    result += EntityUtils.ToString(response.Entity) + Environment.NewLine + "==============" + Environment.NewLine;
                    //}
                    //else
                    //    result += response.ResponseCode.ToString() + Environment.NewLine + "==============" + Environment.NewLine;
                }
                catch (Exception ex)
                {
                    //return ex.ToString();
                }
            }
            return result;
        }
Beispiel #29
0
 /// <summary>
 /// Gets or sets the response code.
 /// </summary>
 /// <value>
 /// The response code.
 /// </value>
 public HttpRestClient()
 {
     client = new HttpClient();
 }
Beispiel #30
0
        public static bool SendSMS(SendCloud sc)
        {
            try
            {
                string sVar = GetVarJson(sc.listVar[0]);

                StringBuilder sb = new StringBuilder();
                sb.Append(sc.API_Key).Append("&");
                sb.Append("phone=").Append(sc.To).Append("&");
                sb.Append("smsUser="******"&");
                sb.Append("templateId=").Append(sc.Template).Append("&");
                sb.Append("vars=").Append(sVar).Append("&");
                sb.Append(sc.API_Key);
                string sSignature = Encryption.UserMd5(sb.ToString());

                HttpClient client = new HttpClient();
                HttpPost postMethod = new HttpPost(new Uri("http://sendcloud.sohu.com/smsapi/send"));

                MultipartEntity multipartEntity = new MultipartEntity();
                postMethod.Entity = multipartEntity;

                multipartEntity.AddBody(new StringBody(Encoding.UTF8, "smsUser", sc.API_User));
                multipartEntity.AddBody(new StringBody(Encoding.UTF8, "signature", sSignature));
                multipartEntity.AddBody(new StringBody(Encoding.UTF8, "templateId", sc.Template));
                multipartEntity.AddBody(new StringBody(Encoding.UTF8, "phone", sc.To));
                multipartEntity.AddBody(new StringBody(Encoding.UTF8, "vars", sVar));

                HttpResponse response = client.Execute(postMethod);

                if (response.ResponseCode == 200)
                {
                    string entity = EntityUtils.ToString(response.Entity);
                    Hashtable ht = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<Hashtable>(entity);
                    if ((string)ht["message"] == "请求成功" && (bool)ht["result"])
                        return true;
                    else
                        return false;
                }
                else
                    return false;
            }
            catch (Exception e)
            {
                return false;
            }
        }
Beispiel #31
0
 /// <summary>
 /// Executes the command
 /// </summary>
 public void Execute()
 {
     HttpClient cli = new HttpClient();
     HttpGet get = new HttpGet(Uri);
     HttpResponse resp = cli.Execute(get);
 }