[RESOLVED] POST string to webapge
Hey guys I have been trying to find a solution for this and I haven't run across anything helpfull so hopefully you can help me here.
This is a windows app not an ASP web app, if that matters.
I am trying to use something like this to POST a string to a webpage on my server. Is this possible from a windows app? I have no idea how to go about it and can't seem to find anything that is helping.
Code:
string sql = "INSERT INTO tblWhatever (field1,field2) VALUES ('1','2')";
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create("");
myReq.Method = "POST";
myReq.ContentType = "application/x-www-form-urlencoded";
StreamWriter writer = new StreamWriter(myReq.GetRequestStream());
writer.Write(sql);
writer.Close();
Alternatively, I have one function that checks to see if an account ID is valid. I would like to send the AccountID to a webapge on my server, have the webpage see if the account is valid then send back a response of "yes or no" to my windows app. Is that possible?
Thanks for any input you can give me!:wave:
Re: POST string to webapge
Why not use a web-service instead. it's type safe and more reliable than this method
Re: POST string to webapge
A web service? I am not even sure what that is. Would that have to be a completely different program or can I integrate it into this Windows app?
Re: POST string to webapge
Quote:
Originally Posted by Arc
A web service? I am not even sure what that is. Would that have to be a completely different program or can I integrate it into this Windows app?
The web service is like a web accessed class library. it can contain methods to be called (executed) remotely and return values. You can google a better definition.
You can include it in your website and reference it from the Windows App
Re: POST string to webapge
My website is made with PHP not asp.net...hrmm
Re: POST string to webapge
This search for 'Arc' works with VBForums (which is a php site ;)
Code:
static void Main(string[] args)
{
string values =
"do=process&showposts=0&quicksearch=1&s=&query=Arc";
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create("http://www.vbforums.com/search.php");
myReq.Method = "POST";
myReq.ContentType = "application/x-www-form-urlencoded";
StreamWriter writer = new StreamWriter(myReq.GetRequestStream());
writer.Write(values);
writer.Close();
HttpWebResponse myResp = (HttpWebResponse)myReq.GetResponse();
Stream stream = myResp.GetResponseStream();
StreamReader reader = new StreamReader(stream);
string response = reader.ReadToEnd();
Console.WriteLine(response);
Console.ReadLine();
}
Re: POST string to webapge
That seems to be working perfectly. Thanks so much for the help!:wave: