using System;
using System.Net.Http;
using System.Windows;
using System.Net;
using System.Text;
using System.IO;
namespace WpfSMShilink
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void SendSMS()
{
DateTime Fecha = DateTime.Now;
var SMS = $"<?xml version='1.0' encoding='UTF-8'?><request><Index>-1</Index><Phones><Phone>";
SMS += Telefono.Text;
SMS += "</Phone></Phones><Sca></Sca><Content>";
SMS += Mensaje.Text;
SMS += "</Content><Length>";
SMS += Mensaje.Text.Length;
SMS += "</Length><Reserved >1</Reserved><Date>";
SMS += Fecha.ToString("yyyy-MM-dd HH:mm:ss");
SMS += "</Date></request>";
var baseAddress = new Uri("http://192.168.8.1");
using (var handler = new HttpClientHandler { UseCookies = false })
{
using (var client = new HttpClient(handler) { BaseAddress = baseAddress })
{
var request = (HttpWebRequest)WebRequest.Create("http://192.168.8.1/api/sms/send-sms");
var postData = SMS;
var data = Encoding.ASCII.GetBytes(postData);
request.Method = "POST";
request.KeepAlive = true;
request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
request.ContentLength = data.Length;
request.Accept = "*/*";
request.Referer="http://192.168.8.1/html/smsinbox.html";
using (var stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
var response = (HttpWebResponse)request.GetResponse();
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
Info.Content=responseString;
}
}
}
private void BtnSend_Click(object sender, RoutedEventArgs e)
{
SendSMS();
}
}
}