PDA

View Full Version : HTTPS ACCESS USING POST/GET METHOD TAKE 2



alex878
12-13-2012, 11:27 PM
Hi guys,

I have posted a thread a while back about using vba to access a https site using a POST/GET request method.

I am really keen in getting this to work and figured I will give it one last shot.

I have created a dummy hotmail account for testing with user name and password alexdummy15@hotmail.com and aldmy434

My Vba code is below which aims to use these log in details to log into hotmail.


Sub test()

Dim HttpReq As Object
Dim URL As String

Set HttpReq = CreateObject("MSXML2.XMLHTTP.5.0")

URL = "https://login.live.com/login.srf?wa=wsignin1.0&rpsnv=11&ct=1355465265&rver=6.1.6206.0&wp=MBI&wreply=http:%2F%2Fmail.live.com%2Fdefault.aspx&lc=1033&id=64855&mkt=en-us&cbcxt=mai&snsc=1"

Set HttpReq = CreateObject("MSXML2.XMLHTTP.5.0")

With HttpReq
.Open "POST", URL, False
.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
.send ("email=alexdummy15@hotmail.com&passwd=aldmy434")
End With

MsgBox HttpReq.responseText

End Sub


The output HTML I get when running the macro is


<!DOCTYPE html><!-- ServerInfo: BAYIDSLGN1K38 2012.11.28.00.36.29 Live1 Unknown LocVer:0 --> <!-- PreprocessInfo: BTSA007:RR1BLDA080, -- Version: 14,0,21184,0 --> <!-- RequestLCID: 1033, Market:EN-US, PrefCountry: US, LangLCID: 1033, LangISO: EN --> <html dir="ltr (http://www.vbaexpress.com/forum/)" lang="EN-US (http://www.vbaexpress.com/forum/)"><head><meta http-equiv="Content-Type (http://www.vbaexpress.com/forum/)" content="text/html; charset=utf-8 (http://www.vbaexpress.com/forum/)"/><meta http-equiv="X-UA-Compatible (http://www.vbaexpress.com/forum/)" content="IE=Edge (http://www.vbaexpress.com/forum/)"/><base href="https://login.live.com/pp1400/ (http://www.vbaexpress.com/forum/view-source:https://login.live.com/pp1400/)"/><script type="text/javascript (http://www.vbaexpress.com/forum/)">var PROOF = {};PROOF.Type = {SQSA: 6, CSS: 5, DeviceId: 4, Email: 1, AltEmail: 2, SMS: 3, HIP: 8, Birthday: 9, TOTPAuthenticator: 10, Voice: -3};</script><noscript><meta http-equiv="Refresh" content="0; URL=https://login.live.com/jsDisabled.srf?mkt=EN-US&lc=1033"/>Microsoft account requires JavaScript to sign in. This web browser either does not support JavaScript, or scripts are being blocked.<br /><br />To find out whether your browser supports JavaScript, or to allow scripts, see the browser's online help.</noscript><title>Sign In</title> <meta name="description (http://www.vbaexpress.com/forum/)" content="Outlook.com is free modern email service from Microsoft. Get a clean clutter�free inbox, easily connect with Office Web Apps and SkyDrive and use it with your Hotmail account. (http://www.vbaexpress.com/forum/)"/><meta name="PageID (http://www.vbaexpress.com/forum/)" content="i5030 (http://www.vbaexpress.com/forum/)"/><meta name="SiteID (http://www.vbaexpress.com/forum/)" content="64855 (http://www.vbaexpress.com/forum/)"/><meta name="ReqLC (http://www.vbaexpress.com/forum/)" content="1033 (http://www.vbaexpress.com/forum/)"/><meta name="LocLC (http://www.vbaexpress.com/forum/)" content="1033 (http://www.vbaexpress.com/forum/)"/><link rel="shortcut icon (http://www.vbaexpress.com/forum/)" href="Https://secure.shared.live.com/~Live.SiteContent.ID/~17.0.10/~/~/~/~/images/favicon.ico (http://www.vbaexpress.com/forum/view-source:https://secure.shared.live.com/%7ELive.SiteContent.ID/%7E17.0.10/%7E/%7E/%7E/%7E/images/favicon.ico)" /> <link rel="stylesheet (http://www.vbaexpress.com/forum/)" title="R3CSS (http://www.vbaexpress.com/forum/)" type="text/css (http://www.vbaexpress.com/forum/)" href="Https://secure.shared.live.com/~Live.SiteContent.ID/~17.0.10/~/~/~/~/css/R3WinLive1033.css (http://www.vbaexpress.com/forum/view-source:https://secure.shared.live.com/%7ELive.SiteContent.ID/%7E17.0.10/%7E/%7E/%7E/%7E/css/R3WinLive1033.css)"/><style type="text/css (http://www.vbaexpress.com/forum/)">:root input[type=checkbox] + label, :root input[type=radio] + label{background-image: url(Https://secure.shared.live.com/~Live.SiteContent.ID/~17.0.10/~/~/~/~/images/controls.png), url(Https://secure.shared.live.com/~Live.SiteContent.ID/~17.0.10/~/~/~/~/images/controls.png), url(Https://secure.shared.live.com/~Live.SiteContent.ID/~17.0.10/~/~/~/~/images/controls.png);} ::-webkit-scrollbar-button{background-image: url(Https://secure.shared.live.com/~Live.SiteContent.ID/~17.0.10/~/~/~/~/images/controls.png);} a, a:visited{color:#0072C6;} a:hover{color:#338ED1;} a:hover:active{color:#66AADC;}

But this however is the HTML code I get when I view the source code from my browser (below) before I log in to hotmail and is not what I want.


<!DOCTYPE html><!-- ServerInfo: BAYIDSLGN1K38 2012.11.28.00.36.29 Live1 Unknown LocVer:0 --> <!-- PreprocessInfo: BTSA007:RR1BLDA080, -- Version: 14,0,21184,0 --> <!-- RequestLCID: 1033, Market:EN-US, PrefCountry: US, LangLCID: 1033, LangISO: EN --> <html dir="ltr (http://www.vbaexpress.com/forum/)" lang="EN-US (http://www.vbaexpress.com/forum/)"><head><meta http-equiv="Content-Type (http://www.vbaexpress.com/forum/)" content="text/html; charset=utf-8 (http://www.vbaexpress.com/forum/)"/><meta http-equiv="X-UA-Compatible (http://www.vbaexpress.com/forum/)" content="IE=Edge (http://www.vbaexpress.com/forum/)"/><base href="https://login.live.com/pp1400/ (http://www.vbaexpress.com/forum/view-source:https://login.live.com/pp1400/)"/><script type="text/javascript (http://www.vbaexpress.com/forum/)">var PROOF = {};PROOF.Type = {SQSA: 6, CSS: 5, DeviceId: 4, Email: 1, AltEmail: 2, SMS: 3, HIP: 8, Birthday: 9, TOTPAuthenticator: 10, Voice: -3};</script><noscript><meta http-equiv="Refresh" content="0; URL=https://login.live.com/jsDisabled.srf?mkt=EN-US&lc=1033"/>Microsoft account requires JavaScript to sign in. This web browser either does not support JavaScript, or scripts are being blocked.<br /><br />To find out whether your browser supports JavaScript, or to allow scripts, see the browser's online help.</noscript><title>Sign In</title> <meta name="description (http://www.vbaexpress.com/forum/)" content="Outlook.com is free modern email service from Microsoft. Get a clean clutter�free inbox, easily connect with Office Web Apps and SkyDrive and use it with your Hotmail account. (http://www.vbaexpress.com/forum/)"/><meta name="PageID (http://www.vbaexpress.com/forum/)" content="i5030 (http://www.vbaexpress.com/forum/)"/><meta name="SiteID (http://www.vbaexpress.com/forum/)" content="64855 (http://www.vbaexpress.com/forum/)"/><meta name="ReqLC (http://www.vbaexpress.com/forum/)" content="1033 (http://www.vbaexpress.com/forum/)"/><meta name="LocLC (http://www.vbaexpress.com/forum/)" content="1033 (http://www.vbaexpress.com/forum/)"/><link rel="shortcut icon (http://www.vbaexpress.com/forum/)" href="Https://secure.shared.live.com/~Live.SiteContent.ID/~17.0.10/~/~/~/~/images/favicon.ico (http://www.vbaexpress.com/forum/view-source:https://secure.shared.live.com/%7ELive.SiteContent.ID/%7E17.0.10/%7E/%7E/%7E/%7E/images/favicon.ico)" /> <link rel="stylesheet (http://www.vbaexpress.com/forum/)" title="R3CSS (http://www.vbaexpress.com/forum/)" type="text/css (http://www.vbaexpress.com/forum/)" href="Https://secure.shared.live.com/~Live.SiteContent.ID/~17.0.10/~/~/~/~/css/R3WinLive1033.css (http://www.vbaexpress.com/forum/view-source:https://secure.shared.live.com/%7ELive.SiteContent.ID/%7E17.0.10/%7E/%7E/%7E/%7E/css/R3WinLive1033.css)"/><style type="text/css (http://www.vbaexpress.com/forum/)">:root input[type=checkbox] + label, :root input[type=radio] + label{background-image: url(Https://secure.shared.live.com/~Live.SiteContent.ID/~17.0.10/~/~/~/~/images/controls.png), url(Https://secure.shared.live.com/~Live.SiteContent.ID/~17.0.10/~/~/~/~/images/controls.png), url(Https://secure.shared.live.com/~Live.SiteContent.ID/~17.0.10/~/~/~/~/images/controls.png);} ::-webkit-scrollbar-button{background-image: url(Https://secure.shared.live.com/~Live.SiteContent.ID/~17.0.10/~/~/~/~/images/controls.png);} a, a:visited{color:#0072C6;} a:hover{color:#338ED1;} a:hover:active{color:#66AADC;} The HTML code I am trying to get from this macro is below and is the HTML when I log into the gmail account and view the source code.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml (http://www.vbaexpress.com/forum/)" style=""> <head> <script type="text/javascript (http://www.vbaexpress.com/forum/)">//<![CDATA[ window["$BSI"]={headTime:(new Date).getTime()};window["$CSIPerf"]={lapse:[{},{s:"h",t:$BSI.headTime}],csd:{},_ttg:$BSI.headTime} //]]></script> <style type="text/css (http://www.vbaexpress.com/forum/)">body{display:none;}</style><script type="text/javascript (http://www.vbaexpress.com/forum/)">//<![CDATA[ var $CJ={"p":"NKfA6G09pAcTSzdhKn6uK4hC25VJzN\u002b4XQxta2aUDtY\u003d0","c":null,"s":1};document.domain="live.com";(function(){var b=1,d=0,a=window,g=a.location.hash,c,h="canary=",f=a.$CJ,e=f.c;try{if(a.self==a.top)b=0;else if(e&&(g.indexOf(h+e)>-1||g.indexOf(h+unescape(e))>-1))b=0;else{try{d=a.parent.$CJ.p==f.p}catch(i){}if(f.s)b=!d}}catch(i){}if(b ){if(d)try{a.top.location=a.location}catch(i){}else try{a.top.location.replace(a.location.href)}catch(i){try{a.top.location=a.l ocation}catch(j){}}c='<plaintext style="display:none">'}else c=unescape("%3C%73")+'tyle type="text/css">body{display:block !important;}</style>';document.write(c)})(); //]]></script> <script type="text/javascript (http://www.vbaexpress.com/forum/)">//<![CDATA[ var _d=document,_dh=_d.getElementsByTagName("head")[0];function _ge(a){return _d.getElementById(a)}var $U={a:"^((ftp|http|https):)?//",isAbsoluteUrl:function(b){var a=new RegExp($U.a,"i");return a.test(b)},doesMatchHost:function(b,d){var f="^(mailto|tel|sms):",h=new RegExp(f,"i"),e=$U.a+"([^:/]*([:][^@/]*)?[@])?([-.a-z0-9]*)[^-.a-z0-9]?",g=new RegExp(e,"i"),k=$U.isAbsoluteUrl(b),a=(String(b).search(g)<0?"":RegExp.$5).toLowerCase(),j=h.test(b),c="."+d,i=a.substr(a.length-c.length)==c||a==""||a.charAt(0)=="#"||a==d;return (!k||i)&&!j},isLinkABookmark:function(a){var c=_d.createElement("span");c.innerHTML='<a href="#"></a>';var e=c.firstChild.href,b=a.indexOf("#"),d=a.indexOf("javascript:");if(b>-1)if(b==0||a.indexOf(e)==0)return 1;if(d==0)return 1;return 0},getUrlFragment:function(c){var a="",b=c.indexOf("#");if(b>-1)a=c.substr(b+1);return a}} //]]></script>



So obviously authorization to the site is not correct. I have also tried sending the user name and password in the format in the vba code which matches the email and username format of the ids in the hotmail HTML code below when I inspect the username and password elements in my firefox browser.


<input id="i0116" class="ltr_override" type="email" lang="en" name="login" maxlength="113" aria-labelledby="idLbl_PWD_Username">
<input id="i0118" type="password" name="passwd" autocomplete="off" aria-labelledby="idDiv_PWD_PasswordExample">

Apparently I need to create headers and the best way to know which headers to use is by viewing the cookies file when I log in to hotmail. Is this correct? If so what details do I need to login to this HTTPS using the POST/GET request method?

Can anyone help with this??? Or help in getting this macro to work???