Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ...
- public void analitic(string inf)
- {
- string phone = inf.Substring(0, inf.IndexOf('?'));
- inf = inf.Substring(inf.IndexOf('?') + 1);
- string source = inf.Substring(0, inf.IndexOf('?'));
- inf = inf.Substring(inf.IndexOf('?') + 1);
- string dest= inf.Substring(0, inf.IndexOf('?'));
- send_post(phone, source, dest);
- }
- public void send_post(string phone,string source,string dest)
- {
- string url = "https://" + dest_ip + ":" + dest_port + "/common_api/1.0/create_order HTTP/1.1";
- string data=null;
- //phone=89123456789&source=SOURCE&source_time=20120501100000&dest=DEST&customer=CUSTOMER&comment=COMMENT&crew_group_id=1
- data += "phone=" + phone + "&";
- data += "source=" + source + "&";
- data+="source_time=20120501100000"+"&";
- data += "dest=" +dest+ "&";
- Console.WriteLine(POST(url,data));
- }
- string POST(string Url, string Data)
- {
- string Out = String.Empty;
- try
- {
- WebRequest req = WebRequest.Create(Url);
- req.Method = "POST";
- req.Timeout = 100000;
- Console.WriteLine(GetHashString(Data));
- //req.Headers.Add("Signature"/*HttpRequestHeader.Authorization*/, GetHashString(Data)+"123");
- byte[] sentData = Encoding.GetEncoding(1251).GetBytes(Data);
- req.ContentLength = sentData.Length;
- Stream sendStream = req.GetRequestStream();
- sendStream.Write(sentData, 0, sentData.Length);
- sendStream.Close();
- WebResponse res = req.GetResponse();
- Stream ReceiveStream = res.GetResponseStream();
- StreamReader sr = new StreamReader(ReceiveStream, Encoding.UTF8);
- Char[] read = new Char[256];
- int count = sr.Read(read, 0, 256);
- while (count > 0)
- {
- String str = new String(read, 0, count);
- Out += str;
- count = sr.Read(read, 0, 256);
- }
- }
- catch
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("404!Ошибка сервера назначения!");
- }
- return Out;
- }
- string GetHashString(string s)
- {
- //переводим строку в байт-массим
- byte[] bytes = Encoding.Unicode.GetBytes(s);
- //создаем объект для получения средст шифрования
- MD5CryptoServiceProvider CSP = new MD5CryptoServiceProvider();
- //вычисляем хеш-представление в байтах
- byte[] byteHash = CSP.ComputeHash(bytes);
- string hash = string.Empty;
- //формируем одну цельную строку из массива
- foreach (byte b in byteHash)
- hash += string.Format("{0:x2}", b);
- return hash;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement