POST info to website from web service

B

Brad

I'm trying to fill out a form on a website from within a web service. I know
there is one field on that form called "call" and I want to put the value
"register" in it. I'm using the following code, but I can't get it to work.
Any Suggestions? I suspect the problem is in the way i'm specifying the
string to send because i get an answer saying the Call parameter was not set:


string myDataString= "<INPUT TYPE=\"hidden\" NAME=\"call\"
VALUE=\"register\">";


HttpWebRequest request = (HttpWebRequest)
WebRequest.Create(ConfigurationSettings.AppSettings["AdidasCUDSite"]);
request.Method = "POST";
request.ContentType = "text/xml";
byte[] postInfo = System.Text.UnicodeEncoding.ASCII.GetBytes(myDataString);
request.ContentLength = postInfo.Length;
Stream s = request.GetRequestStream();
s.Write(postInfo,0,postInfo.Length);

// execute the request
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

// we will read data via the response stream
Stream resStream = response.GetResponseStream();
StreamReader reader = new StreamReader(resStream);
string responseStr = reader.ReadToEnd();
 
B

bruce barker \(sqlwork.com\)

you are confusing html with the postback data. the browser posts data as
name value pairs. also the content type should be
application/x-www-form-.urlencoded. webclient has an uploadvalues that
helps.

-- bruce (sqlwork.com)
 
B

Brad

Thanks for the suggestions but still no love. I tried the different encoding
string but it didn't help, and i tried the following call to uploadvalues but
it returned "500 - internal server error". If you have any more
suggestions, i'd love to hear them.


NameValueCollection myCol = new NameValueCollection();
myCol.Add( "call", "register2" );

string uriString = "http://www.myurl.com/form.asp";
WebClient myWebClient = new WebClient();
byte[] responseArray = myWebClient.UploadValues(uriString,myCol);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top