如何使用用户名和密码发出Http请求 [英] How to make Http request using username and password
本文介绍了如何使用用户名和密码发出Http请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图向一个网站提出Http请求,假设是gmail.com。一旦gmail打开,需要提供用户名,密码。然后我需要获取数据并在我的应用程序中使用它。我能用Java做,但我的项目在MFC中,我使用DHtmalDialog来使用javascript。这是我现在编写的代码。请帮帮我,我是javascript的新手。
//这里调用函数
httpGet(gmail.com); // gmail就是例如
Hi,
I am trying to make Http request to one site suppose "gmail.com". Once gmail opens need to provide username ,password. then I need to get data and use it in my application. I am able to do it in Java, but my project is in MFC and I am using DHtmalDialog to use javascript. here is my code what I have wrote upto now. Please help me I am new in javascript.
// Here calling the function
httpGet("gmail.com"); // gmail is just for example
function httpGet(theUrl)
{
var xmlHttp = null;
xmlHttp = new XMLHttpRequest();
xmlHttp.open("POST", theUrl, false);
xmlHttp.setRequestHeader("username", "invalid");
xmlHttp.setRequestHeader("password", "invalid;);
xmlHttp.setRequestHeader("Content-Type", "application/json");
xmlHttp.setRequestHeader("Accept", "application/json");
xmlHttp.setRequestHeader("Accept-Encoding", "gzip,deflate");
xmlHttp.send();
alert(xmlHttp.readyState); // here I am getting 4
alert(xmlHttp.status); // here I am getting 200
alert(xmlHttp.responseText); // but here it is blank
// xmlHttp.responseType = "json";
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
alert(xmlHttp.responseText); // here also it is blank
}
else {
alert("fail to get status");
}
return xmlHttp.responseText;
}
推荐答案
在这里阅读,
http://eloquentjavascript.net/1st_edition/chapter14.html [ ^ ]
http://stackoverflow.com/questions/220231/accessing-the-web-pages-http-headers -in-javascript [ ^ ]
它会对你有帮助。
Read here,
http://eloquentjavascript.net/1st_edition/chapter14.html[^]
http://stackoverflow.com/questions/220231/accessing-the-web-pages-http-headers-in-javascript[^]
It will help you.
这篇关于如何使用用户名和密码发出Http请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文