Click here to Skip to main content
15,891,708 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

This might sound like a dumb question, but is there a way for me to see what the browser is displaying after I submit a url using Winforms C#?

Basically the following URL is sent using C# and an sms is sent:

C#
string url = "http://api.panaceamobile.com/json?action=message_send&username=" + username + "&password=" + password + "&to=" + recipient +
                         "&text=" + message + "";


If you paste this link in any browser it will display the following if the client's account has a 0 balance:

{"status":-64,"message":"Out of credit"}

This is all wonderful. But I need a way to get the above text that is displayed in the browser to be sent back to my application and store it in a variable.

Is this possible?
Posted

I would suggest you don't use the browser to make the HTTP-request but do it yourself with HttpWebRequest[^]. Then it's easy to get the response directly, without "browser tricks".

A Codeproject-Article showing this:
HttpWebRequest/Response in a Nutshell - Part 1[^]

Google-search for more articles:
https://www.google.com/search?q=c%23+httpclient+codeproject&ie=utf-8&oe=utf-8#q=c%23+httpwebrequest+codeproject[^]
 
Share this answer
 
I figured out the solution myself and will post it here for anyone needing it in future.

I just added the following to my code.

C#
WebClient returnValue = new WebClient();
            string value = returnValue.DownloadString(url);


And then the value variable has the browser text.

Thanks!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900