Solved

C# windows application needs to send a string as a parameter to a webpage

Posted on 2006-07-08
3
943 Views
Last Modified: 2013-12-16
I have a C# windows app that needs to do something like what I have in Javascript here:

$data_string = escape($data_string);            
submitdatawindow = window.open("http://www.somewebpage/submithere.php?data_string=" + $data_string);
submitdatawindow.close();

Basically I need to send a string like an HTML POST (with the escape function) to a web page.

Even better if someone can show me how to POST to a webpage from a C# windows application without actually having to open an IE browser.

Thanks, all
0
Comment
Question by:RichardRiga
3 Comments
 
LVL 1

Author Comment

by:RichardRiga
ID: 17066665
I was looking this up on the web and had a thought... can I open an instance of IE using System.Diagnostics.Process.Start then, when I am finished with it, System.Diagnostics.Process.Kill it?
0
 
LVL 6

Accepted Solution

by:
MuhammadAdil earned 250 total points
ID: 17067222
0
 
LVL 11

Assisted Solution

by:anyoneis
anyoneis earned 250 total points
ID: 17067279
Here is a windows forms app that does this:

[Code]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;    

namespace SendToWebSite
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public DataSet m_DataSet = new DataSet();

        private void button1_Click(object sender, EventArgs e)
        {
            StringBuilder rText = new StringBuilder();

            rText.Append(baseUrlTextBox.Text + '?');
            foreach (DataRow dr in m_DataSet.Tables[0].Rows)
            {
                rText.Append(System.Web.HttpUtility.UrlEncode(dr["Param"].ToString()) + '=');
                rText.Append(System.Web.HttpUtility.UrlEncode(dr["Value"].ToString()) + '&');
            }
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(rText.ToString());
           
            HttpWebResponse resp = (HttpWebResponse)request.GetResponse();
            StreamReader respReader = new StreamReader(resp.GetResponseStream());
            responseTextBox.Text = respReader.ReadToEnd();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("Param", typeof(string));
            dt.Columns.Add("Value", typeof(string));
            m_DataSet.Tables.Add(dt);

            dt.Rows.Add("id", "343");

            parametersDataGridView.DataSource = m_DataSet;
            parametersDataGridView.DataMember = dt.TableName;
        }
    }
}
[/Code]
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…
The purpose of this video is to demonstrate how to Import and export files in WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Click on Too…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now