好日子......
当我”,尝试通过‘短信API’发送短信,我得到了以下异常“不支持的媒体类型415" 。
我从服务提供商
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);
}
当我下面的XML格式,尝试通过‘短信API’发送短信,我得到了以下异常‘不支持的媒体类型415’。 感谢advnace
无关,但如果你换你一次性在'using's你不会需要预先声明它们...而当我将内容类型更改为“application/xml”时,总是使用'Dispose()'它们(显式地或通过'using') – pinkfloydx33