Click here to Skip to main content
15,038,237 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello

i want send sms via C# and huawei 303

the huawei 303 not connect as the COM port.

when i connect it to my computer new network interface and web page appear and i can manage and send sms with http web site like ADSL modem in address http://192.168.1.1 ...

no COM port show on device manager .. only one new network interface ...

can i send SMS via C# with this modem ?
Posted
Updated 11-Jan-21 4:13am

If you cn send SMS using http interface, than what's the problem?
Use Fiddler or IE (10+) Developer toolbar to trach http traffic between your browser and the device. You can than mimic the same actions using WebRequest[^] or HttpClient[^].
   
using System;
using System.Net.Http;
using System.Windows;
using System.Net;
using System.Text; // for class Encoding
using System.IO; // for StreamReader

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();
        }
    }
}
   
Comments
CHill60 11-Jan-21 12:42pm
   
An uncommented code dump is not a solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900