0

Im trying to read a javascript response on my proyect, but im getting the HTML of the page without executing the javascript, here is my code:

  string Url = "MY URL";

  var webRequest = WebRequest.Create(Url);

  using (var response = webRequest.GetResponse())
  using (var content = response.GetResponseStream())
  using (var reader = new StreamReader(content))
  {
    var strContent = reader.ReadToEnd();
  }

In the StrContent im getting the HTML code of the page but no Javascript response, this is what im getting:

<html>
<body>
  <p id="location"></p>
</body>
</html>
<script>
  getLocation();
  var x = document.getElementById("location");
  function getLocation() {
      if (navigator.geolocation) {
          navigator.geolocation.getCurrentPosition(showPosition);
      } else {
          x.innerHTML = "Geolocation is not supported by this browser.";
      }
  }
  function showPosition(position) {
      x.innerHTML = "Latitude: " + position.coords.latitude +
      "<br>Longitude: " + position.coords.longitude;
  }
</script>

i want to read the Longitude and Latitude in my proyect

  • José, you're just downloading the code of the page. **HttpWebRequest does not run what it downloads in a browser.** What are you ***actually*** trying to do? – spender May 18 '15 at 22:16
  • Why don't you call a webservice or api controller from javascript, passing as parameters long and lat? Or this is some kind of web scrapping? – Oscar May 18 '15 at 22:18
  • i have some salesman in the street with laptops and i want their Location when they create a new order but i dont have a GPS so i want to open that javascript code and get the code from there – José Manuel Peña May 18 '15 at 22:31
  • i think this is my solution, let me try (also same html example i use), http://stackoverflow.com/questions/14435585/c-sharp-desktop-application-doesnt-share-my-physical-location – José Manuel Peña May 18 '15 at 22:41

0 Answers0