0

我想使用 asp.net 创建一个授权 http 标头,如果我想使用 php+ curl 执行此操作,我有文档中给出的代码,这里是链接http://help.voxeo.com/go/help/evolution.sms。邮政API

我不想在我的 IIS 上安装 php,只想在 .net 环境中工作。有人可以给asp替代以下代码:

$botkey='[999999]';

$from="14075551212";

$userKey = $_REQUEST['userkey'];

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'http://api.messaging.staging.voxeo.net/1.0/messaging');

curl_setopt($ch, CURLOPT_HEADER, 0);

$data="botkey=".$botkey."&apimethod=send&msg=".$msg."&userkey=".$userKey."&network=SMS&   from=".$from;

curl_setopt($ch, CURLOPT_USERPWD, '[Evolution User Name]:[Evolution Password]');

curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

c    url_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_TIMEOUT, 100);

我需要 ASP.net 替代以下 curl

curl -u MyUserName:MyPassword "http://api.messaging.staging.voxeo.net/1.0/messaging" -X POST -d "botkey=12345&apimethod=send&msg=My%20test%20message.&user=14075555555&network=SMS&from=14076666666"
4

1 回答 1

0

我不确定我是否完全理解你,但这是我必须做的事情才能让 Flash 进入我的应用程序的安全部分。为了清楚起见,我已经删除了更多检查,但如果这是您需要的,这将创建一个授权 cookie。不过我必须要问,为什么不能在 ASP.NET 中使用普通的身份验证方法?

void Application_BeginRequest(object sender, EventArgs e)
{
    string SessionParamName = "";
    string SessionCookieName = "";
    string AuthParamName = "";
    string AuthCookieName = "";

    try
    {
        SessionParamName = "ASPSESSID";
        SessionCookieName = "ASP.NET_SessionId";
        if (HttpContext.Current.Request.Form[SessionParamName] != null)
            UpdateCookie(SessionCookieName, HttpContext.Current.Request.Form[SessionParamName]);
        else if (HttpContext.Current.Request.QueryString[SessionParamName] != null)
            UpdateCookie(SessionCookieName, HttpContext.Current.Request.QueryString[SessionParamName]);
    }
    catch { }

    try
    {
        AuthParamName = "AUTHID";
        AuthCookieName = FormsAuthentication.FormsCookieName;
        if (HttpContext.Current.Request.Form[AuthParamName] != null)
            UpdateCookie(AuthCookieName, HttpContext.Current.Request.Form[AuthParamName]);
        else if (HttpContext.Current.Request.QueryString[AuthParamName] != null)
            UpdateCookie(AuthCookieName, HttpContext.Current.Request.QueryString[AuthParamName]);
    }
    catch { }
}

private void UpdateCookie(string CookieName, string CookieValue)
{
    HttpCookie Cookie = HttpContext.Current.Request.Cookies.Get(CookieName);
    if (Cookie == null)
        Cookie = new HttpCookie(CookieName);

    Cookie.Value = CookieValue;
    HttpContext.Current.Response.Cookies.Add(Cookie);
}
于 2013-01-14T09:03:29.463 回答