4

I tried a lot of things to send an SMS with my Huawei E8372, and nothings works.
here is my last code :

var SMS = $"<?xml version='1.0' encoding='UTF-8'?><request><Index>-1</Index><Phones><Phone>0033*********</Phone></Phones><Sca></Sca><Content>byserver</Content><Length>8</Length><Reserved>1</Reserved><Date>{date.ToString("yyyy-MM-dd HH:mm:ss")}</Date></request>";

//var SMS = $"<request><Index>-1</Index><Phones><Phone>003364*******</Phone></Phones><Sca></Sca><Content>by server</Content><Length>9</Length><Reserved>1</Reserved><Date>{date.ToString("yyyy-MM-dd HH:mm:ss")}</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 message = new HttpRequestMessage(HttpMethod.Post, "/api/sms/send-sms");
        //message.Content = new FormUrlEncodedContent(paramse);
        message.Content = new StringContent(SMS);
        message.Headers.Add("__RequestVerificationToken", token);
        message.Headers.Add("Accept", "*/*");
        message.Headers.Add("Accept-Encoding", "gzip, deflate");
        //message.Headers.Add("Accept-Language", "fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3");
        message.Headers.Add("Connection", "keep-alive");
        //message.Headers.TryAddWithoutValidation("Content-Length", SMS.Length.ToString());
        //message.Headers.TryAddWithoutValidation("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
        message.Headers.Add("Cookie", sessionID);
        //message.Headers.Add("Host","192.168.12.116");
        //message.Headers.Add("Referer", "http://192.168.12.116:61640/Service1.svc/TryThis");
        message.Headers.Add("User-Agent", ".NET Framework Test Client");
        //message.Headers.Add("X-Requested-With", "XMLHttpRequest");
    }
}

I always have 200 in response code. But I never receive my message. I try to change the header a lot of times, to change the body a lot of times too. And I know the modem works, because I can send sms when I use the Interface in my browser. And I send a request like this interfaces does. But that don't work for my application. Maybe is because of a security I don't know or something like that. But I'm blocked since 6 days on this problem and I'm totally desperate.
If one of you have a solution or a clue, I will be very grateful.
Thank you in advance.

P.S : I know HttpClient in an using is not correct. But this is the only one request my application have to do.

EDIT : this is the request who send my browser (with this one that work):
header :

 Host: 192.168.8.1  
 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:64.0) Gecko/20100101 Firefox/64.0
 Accept: */*  
 Accept-Language: fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3  
 Accept-Encoding: gzip, deflate
 Referer: http://192.168.8.1/html/smsinbox.html?smssent  
 Content-Type: application/x-www-form-urlencoded; charset=UTF-8  
 __RequestVerificationToken: 1W7DEw3V5rnPxeg01xqF13kgaPRRtO2d  
 X-Requested-With: XMLHttpRequest  
 Content-Length: 234  
 Connection: keep-alive  
 Cookie: SessionID=1ALPnbTT+SRZMWfPCfVruPnbm0tC4xHWwiumuySJr9AjTaZYzVK4SGYjNmWOEg7lQDsID+RimQ7HIPa3ZRWipdEXIM9APIP8i+K5JUq2yUAhjpZQuCp+Hx+eCQW5tpm/ 

body :

 <?xml version="1.0" encoding="UTF-8"?><request><Index>-1</Index><Phones><Phone>0033646******</Phone></Phones><Sca></Sca><Content>test browser</Content><Length>12</Length><Reserved>1</Reserved><Date>2018-12-21 07:13:04</Date></request>

So this is really similar to the the request from my Application.

lebarillier
  • 5,294
  • 1
  • 9
  • 14
  • "...don't work for my application..." - this information is not really helpful. It does not say what exactly did not work, i.e. did you get any error messages anywhere, did you try to debug the issue to make sure that it actually does the intended thing. – jazb Dec 21 '18 at 05:39
  • this is the real problem, I don't have any error messages. every things looks working perfectly. but the modem don't send the SMS. I found some question about that to use this modem with bash or python, but when I try to do like them It's the same. No error message and no sms received – lebarillier Dec 21 '18 at 05:47
  • You say it works in your computer browser (does the phone really have a web server that can SMS? Wow) so open it in the browser, open the browser developer tools (chrome: f12 key) open the network tab and make a request from start to end including any login. Use the browser Deb tools to analyse what was sent, headers, data, cookies etc and work out where your code goes wrong. The web server probably doesn't care for browser (user agent) etc, but recreate the request exactly and it should work – Caius Jard Dec 21 '18 at 06:03
  • this is exactly what I did (and it's not a phone, it's a USB with a sim card. So, just a modem, and the usual using of it is with a browser) I 'll edit my post with the browser request. – lebarillier Dec 21 '18 at 06:07
  • is it possible to connect your development env using teamviewer or something? if yes please provide me details – Derviş Kayımbaşıoğlu Jan 01 '19 at 20:21
  • @Simonare my apologize, I can't share my development environment. – lebarillier Jan 04 '19 at 02:48
  • Did you find any solution, bro? – NoWar Apr 15 '20 at 06:06
  • no I didn't finished this project. But now I think it's from a problem with oAuth2, I probably didn't have the right to do it, and the modem send a 200 message empty in place of a 401, or 403. But it's just a supposition, – lebarillier Apr 16 '20 at 07:39

1 Answers1

0

Taken from the SO post Sending SMS messages via bash script using a Huawei E8372 hilink

it looks like every command you want to run you have to first get a new token

Since I don't have a Huawei E8372 I'm not able to test this, but you should be able to translate the curl statements in the answer of the post linked to above to C#.

The answer on that post:

The below gets a new token, stored as ADM_TOKEN

curl -s -X GET "http://$MODEM_IP/api/webserver/SesTokInfo" \
 -H "Cookie: $SESSION_ID" > ses_tok2.xml
ADM_TOKEN=`grep "TokInfo" ses_tok2.xml | cut -b 10-41`

and you can then use that ADM_TOKEN to run the next command

curl -v http://192.168.8.1/api/sms/send-sms \
 -H "Cookie: $SESSION_ID" \
 -H "__RequestVerificationToken: $ADM_TOKEN" \
 -H "Content-Type: application/x-www-form-urlencoded; charset=UTF-8" \
 -H "Accept: */*" \
 -H "Referer: http://192.168.8.1/html/smsinbox.html" \
 -H 'X-Requested-With: XMLHttpRequest' \
 -H "Connection: keep-alive" \
 -H "Origin: http://192.168.8.1" \
 --data $message_data \
 --dump-header send_result.txt
rickvdbosch
  • 14,105
  • 2
  • 40
  • 53
  • thank you for your answer and sorry for the time to answer, in first case I recovered the session and the token in one request to `api/webserver/SesTokInfo` after your answer, I take the session in a first request, I put it in a cookie in a second request to get the token, and after I put the cookie and the token in the post request to `api/sms/send-sms` but that still change nothing even with a success answer, I don't receive my sms – lebarillier Jan 04 '19 at 02:46