Hello everyone, I need to do an assignement for school. But i'm kinda stuck on a bit, so i'm here to ask some help :D
Okay, my question:
In my C# application I need to make a webrequest to a php page. This worked, but i want the php page to send a word via the url, only the word is unknown to me. So at this bit, I have this bit of code:

request = (HttpWebRequest)WebRequest.Create("http://www.mywebsite.nl/test.php" + req="?input=);

What I want it to do is, that the string called req takes the value of input, but this input word is unknown to me. This might sound a bit confusing, so if anything isn't clear enough ask me for more information. Thanks in advance for all your help.

Davey.

Recommended Answers

All 9 Replies

Is "input" a string and how is it obtained?

This might be more of a web programming question, which is probably why nobody has responded to your question yet, but go ahead and answer my question and we will see...

Also, please use code tags around your code.

Okay, it is a web application, that is true, but I have the question about the C# part so that is why I put it in here :)
Anyways, the input is just a variabel in the url of the webpage, it could be anything.
But in this case it would be
http://www.mywebsite.nl/test.php?input=... (argument)
I hope this is a bit more clear :)

Thanks,
Davey

OK, so you are constructing a string in C#.

string myString = "http://www.mywebsite.nl/test.php" + inputString;

// or, if input is coming from a control, like a textbox:

string myString = "http://www.mywebsite.nl/test.php" + textBox1.Text;

NOTE: I have not incorporated any symbols you might need in the Uri, like the "?", etc., but you can just add those in your assignment statement:

string s = "http://www.mywebsite.nl/test.php/?input=" + textBox1.Text

I am not a web programmer, so you will excuse me if I didn't construct a syntactically correct Uri string above.:P

Thanks for your reply, I tried it but its sill not working correctly. I will put my code up here, so maybe you can understand it better

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.Data.OleDb;
using System.Xml;
using System.Xml.Schema; 


namespace Connectie_ON_ROP
{
    public partial class Form1 : Form
    {

        StreamReader input;
        HttpWebRequest request;
        HttpWebResponse response;
        string req;
        
        
        
        public Form1()
        {

            InitializeComponent();

        }

        //public void DBCon()
        //{

        //    OleDbConnection DB1 = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Users\\Davey\\Documents\\MVC1.mdb");
        //    string query = "INSERT INTO Tabel1(Gegevens)" + " VALUES ('" + req + "')";
        //    OleDbCommand DbCMD = new OleDbCommand(query, DB1);
        //    DB1.Open();
        //    DbCMD.ExecuteNonQuery();
        //    DB1.Close();

        //}

        public void connect()
        {
            string website = (@"http://www.mywebsite.nl/test.php?input=" + req);
            try
            {
                request = (HttpWebRequest)WebRequest.Create(website);
                response = (HttpWebResponse)request.GetResponse();
                input = new StreamReader(response.GetResponseStream());
                //DBCon();
            }

            catch (Exception ex1)
            {
                MessageBox.Show("Er is iets fout gegaan. \n" + ex1.Message);
            }

        }
        public string read(int lengte)
        {
            char[] array = new char[lengte];
            try
            {
                input.ReadBlock(array, 0, lengte);
            }
            catch
            {
            }
            string output = new string(array);
            return output;
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            req = textBox2.Text;
            connect();
            textBox1.Text = read(100);
            connect();
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }
       

    }
}

Sorry for it being so messy, but i'm still a beginner, and I was planning to make it better when I was finished. If it is not clear, or if I have made you doubt about this all, tell me again haha :)

Thanks,
Davey

Ohh, okay I will do that, thanks for your help :)

You should UrlEncode all data sent as part of the URL structure with HttpUtility.UrlEncode() . This can be found in the System.Web namespace.

commented: chic +6

wot is the problem...

thorugh webrequest you fire the php page and get the response as html...now store the response in the temporary string variable and use string.contains...

if it matches...then i guess u 've done..it

hope that helps...cos i've created the same application in my website...

What do you mean with "fire the php page" ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.