OK it deserts this to put it in a new thread.
I've found this:

using System;
using System.Net;
using System.Web;
using System.Collections;
using System.IO;

namespace WebRequestExample
{

    class WebPostRequest
    {
        WebRequest theRequest;
        HttpWebResponse theResponse;
        ArrayList theQueryData;

        public WebPostRequest(string url)
        {
            theRequest = WebRequest.Create(url);
            theRequest.Method = "POST";
            theQueryData = new ArrayList();
        }

        public void Add(string key, string value)
        {
            theQueryData.Add(String.Format("{0}={1}", key, HttpUtility.UrlEncode(value)));
        }

        public string GetResponse()
        {
            // Set the encoding type
            theRequest.ContentType = "application/x-www-form-urlencoded";

            // Build a string containing all the parameters
            string Parameters = String.Join("&", (String[])theQueryData.ToArray(typeof(string)));
            theRequest.ContentLength = Parameters.Length;

            // We write the parameters into the request
            StreamWriter sw = new StreamWriter(theRequest.GetRequestStream());
            sw.Write(Parameters);
            sw.Close();

            // Execute the query
            theResponse = (HttpWebResponse)theRequest.GetResponse();
            StreamReader sr = new StreamReader(theResponse.GetResponseStream());
            return sr.ReadToEnd();
        }

    }

    class MainClass
    {
        public static void Main(string[] args)
        {
            WebPostRequest myPost = new WebPostRequest("http://localhost/sensor.php");
            //Post.Add("keyword", "void");
            myPost.Add("data", "hello&+-[]");
            Console.WriteLine(myPost.GetResponse());
            Console.ReadLine();
        }
    }
}

I want these values "hello&+-[]" to display it to my IE.

My php script is

    <?
       echo $_POST['data']; // so simple....
    ?>

But php cannot display my data.C# on the other side to the point GetResponse prints my data just fine.But i want php to preview my results and not C#
Please help me!!!!

Thanks

Dani AI

Generated

— two likely causes and simple checks.

First, PHP parsing: the posted snippet uses short tags (<? ... ?>). Many PHP installs have short_open_tag disabled, so <? will not be executed as PHP. Replace the short tag with the full opening tag (<?php ... ?>) or enable short_open_tag in php.ini. As suggested, dump the incoming request (inspect $_REQUEST or read the raw body) to confirm what the server actually receives.

Second, the C# client: make sure the form body is encoded and sent exactly as the server expects. Build the URL-encoded string using & (not the HTML &amp;), then compute and send the byte length of the payload — not the string character count. Example pattern (conceptual):

byte[] payload = Encoding.UTF8.GetBytes(parameters);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = payload.Length;
using (Stream s = request.GetRequestStream())
    s.Write(payload, 0, payload.Length);

Also ensure values are URL-encoded before concatenation.

Note on previewing in IE: a programmatic POST made by the C# app returns the response to that app; IE will not automatically show it. To view the server output in a browser either submit the same POST from a simple HTML form (method=POST) or log/echo the received data server-side and open the page in IE. For packet-level debugging, a proxy like Fiddler or a tool like Postman/curl helps validate exactly what the server saw.

Hi, maybe you should try $_REQUEST because this contains both the GET and POST parameters.
To find out what has been sent to your PHP server you can dump the content of the variables with var_export:

<?
    //either
    var_export($_REQUEST);
    //or
    print var_export($_REQUEST, true);
?>

This dumps the complete content of your request parameters to your page.
Good luck

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.