D
David
Hi all,
I am trying to send an SMS and am having problem sending the UK Pound
symbol, £
It appears to be crashing out on the streamwriter line. The result I am
getting is...
System.Net.WebException: The request was aborted: The request was
canceled. ---> System.IO.IOException: Cannot close stream until all bytes
are written.
I have tried a number of encodings, but it appears to come through as a ? or
a square (when it doesn't crash out). What encoding should I use?
As mentioned in another message, I am using
http://www.txtlocal.co.uk/signup/ as my SMS provider.
public string SendMessage(string From, string Number, string Message)
{
string result = string.Empty;
string strPost = string.Empty;
string SMSUrl = ConfigurationManager.AppSettings["SMSUrl"];
string User = ConfigurationManager.AppSettings["SMSUser"];
string Pass = ConfigurationManager.AppSettings["SMSPass"];
Number = Number.Replace("+", string.Empty);
string TestMode = string.Empty;
try
{
if
(ConfigurationManager.AppSettings["SMSTestMode"].ToLower() == "true")
{
TestMode = "&test=1";
//Number = "998" + Number;
}
}
catch
{
}
strPost = "uname=" + User + "&pword=" + Pass + "&message=" +
Message + "&from=" + From + "&selectednums=" + Number + "&info=1" +
TestMode;
StreamWriter myWriter = null;
HttpWebRequest objRequest =
(HttpWebRequest)WebRequest.Create(SMSUrl);
//add Proxy info if required
//objRequest.Proxy = WebProxy.GetDefaultProxy();
//objRequest.Proxy.Credentials =
CredentialCache.DefaultCredentials; //uses logged on user
//objRequest.Proxy.Credentials = new
System.Net.NetworkCredential("UserName", "Password"); // Alternative -
specify the user and password to use
objRequest.Method = "POST";
objRequest.ContentLength = strPost.Length;
objRequest.ContentType = "application/x-www-form-urlencoded";
try
{
myWriter = new StreamWriter(objRequest.GetRequestStream());
myWriter.Write(strPost);
}
catch (Exception e)
{
return e.Message;
}
finally
{
myWriter.Close();
}
HttpWebResponse objResponse =
(HttpWebResponse)objRequest.GetResponse();
using (StreamReader sr = new
StreamReader(objResponse.GetResponseStream()))
{
result = sr.ReadToEnd();
// Close and clean up the StreamReader
sr.Close();
}
return result;
}
--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
I am trying to send an SMS and am having problem sending the UK Pound
symbol, £
It appears to be crashing out on the streamwriter line. The result I am
getting is...
System.Net.WebException: The request was aborted: The request was
canceled. ---> System.IO.IOException: Cannot close stream until all bytes
are written.
I have tried a number of encodings, but it appears to come through as a ? or
a square (when it doesn't crash out). What encoding should I use?
As mentioned in another message, I am using
http://www.txtlocal.co.uk/signup/ as my SMS provider.
public string SendMessage(string From, string Number, string Message)
{
string result = string.Empty;
string strPost = string.Empty;
string SMSUrl = ConfigurationManager.AppSettings["SMSUrl"];
string User = ConfigurationManager.AppSettings["SMSUser"];
string Pass = ConfigurationManager.AppSettings["SMSPass"];
Number = Number.Replace("+", string.Empty);
string TestMode = string.Empty;
try
{
if
(ConfigurationManager.AppSettings["SMSTestMode"].ToLower() == "true")
{
TestMode = "&test=1";
//Number = "998" + Number;
}
}
catch
{
}
strPost = "uname=" + User + "&pword=" + Pass + "&message=" +
Message + "&from=" + From + "&selectednums=" + Number + "&info=1" +
TestMode;
StreamWriter myWriter = null;
HttpWebRequest objRequest =
(HttpWebRequest)WebRequest.Create(SMSUrl);
//add Proxy info if required
//objRequest.Proxy = WebProxy.GetDefaultProxy();
//objRequest.Proxy.Credentials =
CredentialCache.DefaultCredentials; //uses logged on user
//objRequest.Proxy.Credentials = new
System.Net.NetworkCredential("UserName", "Password"); // Alternative -
specify the user and password to use
objRequest.Method = "POST";
objRequest.ContentLength = strPost.Length;
objRequest.ContentType = "application/x-www-form-urlencoded";
try
{
myWriter = new StreamWriter(objRequest.GetRequestStream());
myWriter.Write(strPost);
}
catch (Exception e)
{
return e.Message;
}
finally
{
myWriter.Close();
}
HttpWebResponse objResponse =
(HttpWebResponse)objRequest.GetResponse();
using (StreamReader sr = new
StreamReader(objResponse.GetResponseStream()))
{
result = sr.ReadToEnd();
// Close and clean up the StreamReader
sr.Close();
}
return result;
}
--
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available