WebRequest Help Required.... RRS feed

  • Question

  • User1010253313 posted

    Can anyone help with this problem, I am trying to send a form post via inline code.
    The code is to be automated so hence to form post.

    I have tried the following code and whilst my test recieve form recieves a data stream the content of it can not be resolved back to give me a sensible querystring...

    I would appreciate it if any experts out there could take a look and let me know where I am going wrong.



    private void btnSubmit_Click(object sender, System.EventArgs e)


    txtResult.Text = readHtmlPage("http://localhost/IntranetApplications/recievepost/WebForm1.aspx");

    //txtResult.Text = readHtmlPage("http://dmconnect.edc.dartmail.com/dmconnect/dmconnect.exe");


    private String readHtmlPage(string url)


    string result = "";

    string postData;

    postData = "Servername=" + Servername.Value;

    postData += "&Username=" + Username.Value;

    postData += "&Password=" + Password.Value;

    postData += "&AcknowledgementTo=" + AcknowledgementTo.Value;

    postData += "&XML=" + XML.Value;

    StreamWriter myWriter = null;

    HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(url);

    objRequest.Method = "POST";

    objRequest.ContentLength = postData.Length;

    //objRequest.ContentType = "application/x-www-form-urlencoded";

    objRequest.ContentType = "text/xml";

    // Set Proxy

    WebProxy myProxy=new WebProxy();


    string proxyAddress = "proxy address";

    // Create a new Uri object.

    Uri newUri=new Uri(proxyAddress);

    // Associate the newUri object to 'myProxy' object so that new myProxy settings can be set.


    // Create a NetworkCredential object and associate it with the Proxy property of request object.

    myProxy.Credentials=new NetworkCredential("user","pass");





    myWriter = new StreamWriter(objRequest.GetRequestStream());



    catch (Exception e)


    return e.Message;


    finally {



    HttpWebResponse objResponse = (HttpWebResponse)objRequest.GetResponse();

    using (StreamReader sr =

    new StreamReader(objResponse.GetResponseStream()) )


    result = sr.ReadToEnd();

    // Close and clean up the StreamReader



    return result;



    Tuesday, January 31, 2006 4:43 AM

All replies

  • User-1372641848 posted

    Probaby this working sample might help you.

    Posting form data to remote website using HttpWebRequest

    Wednesday, February 1, 2006 7:43 PM
  • User1010253313 posted

    Still no joy,  I am still getting the same problem when trying to read the querystring back.

    reader.ReadToEnd() = recieves the following


    However when my app recieves the post...


    I get the following

    Object reference not set to an instance of an object.


    I am assuming the post is not correctly specified.



    Thursday, February 2, 2006 5:19 AM