本文介绍了如何在C#Windows窗体应用程序中编写此Javascript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在C#windows窗体应用程序中编写Web客户端。然后我在java脚本中找到了这个示例代码。我不熟悉。那么如何在C#中编写相同的函数呢?
I'm writing web client in C# windows forms application. Then I found this sample code in java script. which i'm not familiar with. So how can i write same functions in C#???
function get_token(username,password){
var xhr = new XMLHttpRequest();
xhr.open("POST", "http://your_ABC_domain.com/oauth/token", true);
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhr.onreadystatechange=function(e){
if (xhr.readyState==4 && xhr.status==200){
console.log(e.target.responseText);
}
}
token=xhr.send("client_id=53a305cab608748as64eb6224831dab772105a989d8e454d4a8d8183afb560c414e2eflient_secret=95318fad811212710db49aec17353c5983c10a1454cheadfthisis25sa25mp25le26a95e19c7c87dec332&grant_type=password&username="+username+"&password="+password+"redirect_uri=http://localhost:3001/authorize");
return(token);
}
function callApi(token, path)
{
var httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = function(evt)
{
console.log("xhr.readyState :: "+httpRequest.readyState);
console.log("xhr.status :: "+httpRequest.status);
if (httpRequest.readyState==4 && httpRequest.status==200)
{
console.log(evt.target.responseText);
}
}
httpRequest.open('GET', 'http://your_ABC_domain.com/api/'+path);
httpRequest.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
httpRequest.setRequestHeader('Authorization', 'Token token="'+token+'"');
httpRequest.send();
}
推荐答案
function get_token(username,password){
var xhr = new XMLHttpRequest();
xhr.open("POST", "http://your_ABC_domain.com/oauth/token", true);
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhr.onreadystatechange=function(e){
if (xhr.readyState==4 && xhr.status==200){
console.log(e.target.responseText);
}
}
token=xhr.send("client_id=53a305cab608748as64eb6224831dab772105a989d8e454d4a8d8183afb560c414e2eflient_secret=95318fad811212710db49aec17353c5983c10a1454cheadfthisis25sa25mp25le26a95e19c7c87dec332&grant_type=password&username="+username+"&password="+password+"redirect_uri=http://localhost:3001/authorize");
return(token);
}
function callApi(token, path)
{
var httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = function(evt)
{
console.log("xhr.readyState :: "+httpRequest.readyState);
console.log("xhr.status :: "+httpRequest.status);
if (httpRequest.readyState==4 && httpRequest.status==200)
{
console.log(evt.target.responseText);
}
}
httpRequest.open('GET', 'http://your_ABC_domain.com/api/'+path);
httpRequest.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
httpRequest.setRequestHeader('Authorization', 'Token token="'+token+'"');
httpRequest.send();
}
%>
%>
这篇关于如何在C#Windows窗体应用程序中编写此Javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!