Dears,
Good day...
when I', trying to send SMS via "SMS API" , I got the following exception "Unsupported media type 415".
I got the following xml format from the service provider
System.Net.WebRequest req = null;
System.Net.WebResponse rsp = null;
System.IO.StreamWriter writer;
System.IO.StreamReader Reader;
String responseFromServer;
String uri;
String txtXMLData;
String AccountId;
String Password;
String SecureHashSecretKey;
String SenderName;
String MSISDN;
String SMSMessage;
try
{
AccountId = "xxxxx";
Password = "xxxxx";
SecureHashSecretKey = "xxxxx";
SenderName = "xxxxx";
MSISDN = "xxxxx";
SMSMessage = "Test SMS";
uri = "https://e3len.vodafone.com.eg/web2sms/sms/submit/";
txtXMLData = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<SubmitSMSRequest xmlns:=\"http://www.edafa.com/web2sms/sms/model/\""+
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""+
"xsi:schemaLocation=\"http://www.edafa.com/web2sms/sms/model/ SMSAPI.xsd \" xsi:type=\"SubmitSMSRequest\">"+
"<AccountId>"+AccountId+"</AccountId>"+
"<Password>"+Password+"</Password>"+
"<SecureHash>"+SecureHashSecretKey+"</SecureHash>"+
"<SMSList>"+
"<SenderName>"+SenderName+"</SenderName>"+
"<ReceiverMSISDN>"+MSISDN+"</ReceiverMSISDN>"+
"<SMSText>"+SMSMessage+"</SMSText>"+
"</SMSList>"+
"</SubmitSMSRequest>";
req = System.Net.WebRequest.Create(uri);
req.Method = "POST";
req.ContentType = "text/xml";
writer = new System.IO.StreamWriter(req.GetRequestStream());
writer.WriteLine (txtXMLData);
writer.Close ();
rsp = req.GetResponse();
Reader = new System.IO.StreamReader(rsp.GetResponseStream());
responseFromServer = Reader.ReadToEnd();
rsp.Close();
Reader.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
when I', trying to send SMS via "SMS API" , I got the following exception "Unsupported media type 415". Thanks in advnace
Try changing the ContentType to
application/xml
Sometimes APIs can be pretty strict with what they accept.
I'd also try setting the Accept header, this tells the API what you can handle too.