使用ASP.NET授权HTTP头



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

我不想在我的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"

我不确定我完全理解你,但这是我必须做的事情,以允许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);
}

最新更新