2

I have a problem which I am sure has a simple solution, but I haven't encountered before.

I have a HTML file, which calls a JavaScript API and retrieves values - this particular case calls a mapping API and retrieves co-ordinates when passed a postcode. However, for arguments sake, I will simplify to the following:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<script>
  
  $(document).ready(function() {
  
    $("#myDiv").text("xValue,yValue");      
  });
  </script>

<div id="myDiv">
  </div>

However, as a .net HTTP GET request, this returns the page source, which has the empty div without the values injected:

var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://mywebsite.com/myfile.html");
httpWebRequest.ContentType = "text/html";
httpWebRequest.Method = "GET";

var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
    var result = streamReader.ReadToEnd();
}

There must be a better solution to this problem - I am only able to retrieve the values through JavaScript.

LoveFortyDown
  • 1,011
  • 2
  • 17
  • 37
  • 1
    Try opening the developer tools in your browser (usually F12) and moving to the network tab. This lets you see what your browser is sending/recieving. You might be able to send a request to the mapping API and get the values that way. – fallaciousreasoning Feb 05 '15 at 09:15
  • possible duplicate of [C# httpwebrequest and javascript](http://stackoverflow.com/questions/516027/c-sharp-httpwebrequest-and-javascript) – VMAtm Feb 05 '15 at 09:17
  • @fallaciousreasoning I did not think of that - managed to find a solution using the API request, good thinking! – LoveFortyDown Feb 06 '15 at 08:57

0 Answers0