我想使用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"
答案 0 :(得分: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);
}