amberl
amberl

Reputation: 81

requesting a webpage and not returning the same html

I'm using System.Net.Http to return a webpage. Compared to the actual login page I can't figure out why it's not returning the login table I need.

 var loginUrl = "https://prowand.pro-unlimited.com/login.html";
 CookieContainer cookies = new CookieContainer();
 HttpClientHandler handler = new HttpClientHandler();
 handler.CookieContainer = cookies;
 HttpClient client = new HttpClient(handler);
 //login
 var resp1 = await client.GetAsync(loginUrl);
 var content1 = await resp1.Content.ReadAsStringAsync();

It doesn't return the same information. Is it because of JavaScript?

enter image description here

Upvotes: 0

Views: 46

Answers (2)

Equalsk
Equalsk

Reputation: 8194

You need to add a User Agent String to your client.

HttpClient client = new HttpClient(handler);

// User Agent String header
// Can be a different user agent if you like, your choice
client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36");

var resp1 = await client.GetAsync(loginUrl);
var content1 = await resp1.Content.ReadAsStringAsync();

The User Agent String tells the website that you're a particular browser. It's often used by the website to determine how to layout the page. In this case when this page detects no string it throws an error.

Upvotes: 2

jdweng
jdweng

Reputation: 34429

The login window is in following html which is not a script

                <label class='block' style='margin-top:55px;'>Username</label>
                <input id="usernamefield" name="username" class="block full-width" type="text" autocomplete="off" htmlEscape="true"> 

                <label class='block m-t-xl'>Password</label>
                <input id="passwordfield" class="block full-width m-b-sm" name="password" type="password" autocomplete="off" htmlEscape="true"> 

                <a href='/login_help.html'>Need Help?</a>

                <button type='submit' name="loginButton" class='btn btn-success m-t-xl p-t-md floatright'>Log in</button>

Upvotes: 0

Related Questions