string url = string.Format(
"http://bms.hichina.com/sms_gateway/sms_api?"
+ "user_id={0}&password={1}&mobile_phone={2}"
+ "&msg={3}&send_date={4}&subCode={5}"
, string.Empty //用户id
, string.Empty //密码
, string.Empty //电话号码
, Server.UrlEncode(string.Empty) //短信消息
, Server.UrlEncode(string.Empty) //发送日期
, string.Empty //企业号
);
System.Net.WebClient client = new System.Net.WebClient();
client.Encoding = System.Text.Encoding.UTF8; //指定编码
string reply = client.DownloadString(url);
Response.Write(reply);
//string url = "/SupplyAJAX.aspx";
//string strResult = GetRequestJsonString(url, "type=getcount");
#region 后台获取ashx返回的数据
/// <summary>
/// 后台获取ashx返回的数据
/// </summary>
/// <param name="relativePath">地址</param>
/// <param name="data">参数</param>
/// <returns></returns>
public static string GetRequestJsonString(string relativePath, string data)
{
string requestUrl = GetRequestUrl(relativePath, data);
try
{
WebRequest request = WebRequest.Create(requestUrl);
request.Method = "GET";
StreamReader jsonStream = new StreamReader(request.GetResponse().GetResponseStream());
string jsonObject = jsonStream.ReadToEnd();
return jsonObject;
}
catch
{
return string.Empty;
}
}
public static string GetRequestUrl(string relativePath, string data)
{
string absolutePath = HttpContext.Current.Request.Url.AbsoluteUri;
string hostNameAndPort = HttpContext.Current.Request.Url.Authority;
string applicationDir = HttpContext.Current.Request.ApplicationPath;
StringBuilder sbRequestUrl = new StringBuilder();
sbRequestUrl.Append(absolutePath.Substring(0, absolutePath.IndexOf(hostNameAndPort)));
sbRequestUrl.Append(hostNameAndPort);
sbRequestUrl.Append(applicationDir);
sbRequestUrl.Append(relativePath);
if (!string.IsNullOrEmpty(data))
{
sbRequestUrl.Append("?");
sbRequestUrl.Append(data);
}
return sbRequestUrl.ToString();
}
#endregion
}