0

I am creating a chat application and I am using a free webhosting to store the online users in a database. I have the following structure:

1) index.php where i get the online users in this format:

<user>
   <name></name>
   <ip></ip>
</user>

2) add.php?user= to add a new user to the database when he connects.

3) remove.php?user= to remove a user when he disconnects.

Now in the application I have a function GetUsers() like this:

string url = @"http://.../index.php";
System.Net.WebRequest req = System.Net.WebRequest.Create(url);

System.Net.WebResponse res = (System.Net.WebResponse)req.GetResponse();

If I am using the local IIS server for the url it works but when I try with the free webhosted url it gives me an 406 Not Acceptable error. So I think I need to put some headers or something to fake a real browser.

UPDATE: 1) The free hosting service is using Apache as the webserver. 2) You can suggest another approach to fetch the web page.

Sp3ct3R
  • 715
  • 1
  • 12
  • 24
  • 1
    I suggest using a tool like fiddler to capture your browser's requests, and then trying to simulate them in code. – argaz Jun 22 '13 at 10:45
  • @argaz thanks for the comment I indeed found that the problem was the `User-Agent` header. So post an Answer or something so i can accept it. – Sp3ct3R Jun 22 '13 at 11:13

1 Answers1

0

I suggest using a tool like Fiddler to capture your browser's requests, and then trying to simulate them in code.

You can also route your programmatic requests through Fiddler using the technique from this answer. Shortly:

req.Proxy = new WebProxy("http://localhost:8888", false);

localhost:8888 is the default address of Fiddler.

Community
  • 1
  • 1
argaz
  • 1,458
  • 10
  • 15