POST info to website from web service

Discussion in 'ASP .Net Web Services' started by Brad, Oct 3, 2006.

  1. Brad

    Brad Guest

    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();
     
    Brad, Oct 3, 2006
    #1
    1. Advertising

  2. 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)

    "Brad" <> wrote in message
    news:...
    > 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();
    >
     
    bruce barker \(sqlwork.com\), Oct 4, 2006
    #2
    1. Advertising

  3. Brad

    Brad Guest

    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);
     
    Brad, Oct 5, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Vasanth
    Replies:
    0
    Views:
    575
    Vasanth
    Jun 28, 2004
  2. Andrea Williams

    Clear the Render info & change to different info

    Andrea Williams, Oct 27, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    1,437
    Ken Dopierala Jr.
    Oct 27, 2004
  3. Kiran
    Replies:
    0
    Views:
    1,239
    Kiran
    Feb 6, 2005
  4. sravan kumar
    Replies:
    0
    Views:
    449
    sravan kumar
    Jun 21, 2011
  5. Leo Violette
    Replies:
    0
    Views:
    1,068
    Leo Violette
    Apr 17, 2009
Loading...

Share This Page