我有重定向:
rest_data<-fulldata[-which(fulldata$ID%in%training_data$ID),]
这导致我的浏览器重定向到
https://www.example.com/auth/linkedin?code=CODE_I_NEED&state=STATE
如何检索代码参数的值?
string linkedInLogin = "https://www.linkedin.com/oauth/v2/authorization?response_type=code&client_id=ID&redirect_uri=https%3A%2F%2Fwww.example.com%2Fauth%2Flinkedin&state=ZEKNI&scope=r_basicprofile";
Response.Redirect(linkedInLogin);
为我提供Request.Querystring["code"]
值。问题是浏览器“认为”当前网址为null
。
答案 0 :(得分:1)
尝试:
HttpContext.Current.Request.Params["code"]
通过这种方式,您可以获得QueryString
,Form
,Cookies
和ServerVariables
个项目的综合集合。
在这里,您可以阅读更多内容:HttpRequest.Params Property
答案 1 :(得分:1)
您是否将链接存储在某处或者您是否要求如何检索它?
假设你已经拥有它:
var s = "https://www.example.com/auth/linkedin?
code=CODE_I_NEED&state=ROB962242SMUT"
您可以这样做:
string s = "https://www.example.com/auth/linkedin?code=CODE_I_NEED&state=ROB962242SMUT";
var code = s.Substring((s.IndexOf("code=") + 5), (s.IndexOf('&') - (s.IndexOf("code=") + 5)));
//CODE_I_NEED
或者
String sourcestring = "https://www.example.com/auth/linkedin?
code=CODE_I_NEED&state=ROB962242SMUT";
Regex re = new Regex(@"code=(.*)&");
var result =Match m = re.Match(sourcestring).Value;
//CODE_I_NEED
编辑:根据其他两个答案,我可能没有正确理解你的问题xd