I build a asp.net core razor page website
www.mywebsite.com/wx. There is a api server
https://api.outerserver.com/server .When the outer api server post a xml data to mywebsite
www.mywebsite.com/wx ,My project‘s task is todo two thing ,the first task is get a token from thehttps://api.outerserver.com/server/gettoken ,the Second task my project read theXml data ,and reply the same xml data to the outer api server.
Above can be done in mvc project or asp.net webform project.
How to do it in asp.net core razor page project. please show me a sample.
public static string GetAccessToken(string corpid, string corpsecret)
{
string getAccessTokenUrl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}";
string accessToken = ""; string respText = "";
string url = string.Format(getAccessTokenUrl, corpid, corpsecret);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse(); using (Stream resStream = response.GetResponseStream())
{
StreamReader reader = new StreamReader(resStream, Encoding.Default);
respText = reader.ReadToEnd();
resStream.Close();
}
try
{
int start = respText.IndexOf("access_token");
int end = respText.IndexOf("expires_in");
start += 15;
end -= 3;
respText = respText.Substring(start, end - start);
accessToken = respText;
}
catch (Exception ex) { }; return accessToken;
}