Solved

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

Posted on 2006-07-08
3
952 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When setting up new project requests for our site, one of the most powerful tools our team has available to use is Axure (http://www.axure.com/). It’s a tool for creating software and web prototypes that can function and interact as if it were the a…
Introduction In this tutorial, I'll explain how to create an animated progress meter in a wireframe prototype developed using Axure RP 7.0 - a leading prototyping tool for designing web sites and software. (For more information about Axure and gett…
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…

776 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