Click here to Skip to main content
15,884,836 members
Home / Discussions / C#
   

C#

 
AnswerRe: Taking voice input in C# in Visual Studio Pin
Abhinav S10-Jun-12 20:46
Abhinav S10-Jun-12 20:46 
QuestionC# windows forms sent data to a link and preview them with PHP on IE or Safari etc. Pin
Vvelawras10-Jun-12 9:24
Vvelawras10-Jun-12 9:24 
AnswerRe: C# windows forms sent data to a link and preview them with PHP on IE or Safari etc. Pin
Abhinav S10-Jun-12 17:20
Abhinav S10-Jun-12 17:20 
GeneralRe: C# windows forms sent data to a link and preview them with PHP on IE or Safari etc. Pin
Vvelawras10-Jun-12 21:58
Vvelawras10-Jun-12 21:58 
AnswerRe: C# windows forms sent data to a link and preview them with PHP on IE or Safari etc. Pin
BobJanova10-Jun-12 22:58
BobJanova10-Jun-12 22:58 
GeneralRe: C# windows forms sent data to a link and preview them with PHP on IE or Safari etc. Pin
Vvelawras10-Jun-12 23:04
Vvelawras10-Jun-12 23:04 
GeneralRe: C# windows forms sent data to a link and preview them with PHP on IE or Safari etc. Pin
BobJanova11-Jun-12 5:54
BobJanova11-Jun-12 5:54 
QuestionReceive post values from Windows form app C# with php Pin
Vvelawras10-Jun-12 9:18
Vvelawras10-Jun-12 9:18 
CSS
Hello everybody!I want to ask you something. I want to send values from C# windows form application in php webpage.In other words send post values from C# to php.

The problem is that php script cannot read this values and preview this results which comes from C# app.Could you help me please?

Here is the C# code:


using System;
using System.Net;
using System.Web;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Text;
using System.IO;

namespace WebRequestExample
{

    class WebPostRequest
    {
     
        public string Post(IDictionary<string, string> objects)
        {
            // Create a request using a URL that can receive a post. 
            WebRequest request = WebRequest.Create("http://127.0.0.1/sensor.php");
            // Set the Method property of the request to POST.
            request.Method = "POST";
            // Create POST data and convert it to a byte array.

            StringBuilder b = new StringBuilder();
            foreach (KeyValuePair<string, string> o in objects)
                b.Append("?").Append(HttpUtility.UrlEncode(o.Key)).Append("=").Append(HttpUtility.UrlEncode(o.Value ?? ""));            
            string postData = b.ToString(1, b.Length-1);            

            byte[] byteArray = Encoding.UTF8.GetBytes(postData);
            request.ContentType = "application/x-www-form-urlencoded";
            request.ContentLength = byteArray.Length;
            Stream dataStream = request.GetRequestStream();
            dataStream.Write(byteArray, 0, byteArray.Length);
            dataStream.Close();
            WebResponse response = request.GetResponse();


            if (((HttpWebResponse)response).StatusCode != HttpStatusCode.OK)
                return null;


            dataStream = response.GetResponseStream();
            StreamReader reader = new StreamReader(dataStream);
            string responseFromServer = reader.ReadToEnd();            
            reader.Close();

            dataStream.Close();
            response.Close();

            return responseFromServer;

        }
            
        class MainClass
        {
            public static void Main(string[] args)
            {
                /*NameValueCollection postData = new NameValueCollection();
                postData.Add("data", "hello world");
                WebClient client = new WebClient();
                client.Encoding = Encoding.UTF8;
                byte[] response = client.UploadValues("http://localhost/sensor.php", "POST", postData);
                string result = Encoding.UTF8.GetString(response);
                Console.WriteLine(result);*/
                WebPostRequest a = new WebPostRequest();
                IDictionary<string, string> postData = new Dictionary<string, string>();
                
                postData.Add("data", "123156564648989");
                Console.WriteLine(a.Post(postData));
                ///System.Diagnostics.Process.Start("http://localhost/sensor.php?data=123");               
                
                Console.ReadLine();
             }            
        } 
    }    
}

SQL
And a very simple php script to display the post data!
   <?
    <pre> print_r($_POST); 
	echo $_POST['data']; 
	echo '<br>';
	echo $_REQUEST['data']; 
	echo '<br>';
	var_dump( $_REQUEST); 
	echo '<br>';
	
	echo '<file_get_contents>';
	$postdata = trim(file_get_contents('php://input'));
	$postdata = urldecode($postdata); 
	var_dump( $postdata);
	echo '<br>';	 
?> 

?>

Could you help me please? I repeat that the problems is that PHP cannot preview the POST data which becomes from C# windows form application. It always returns NULL.

Thanks alot!
All the truth becomes from knowledge...

QuestionEnable multiple textboxes one by one on button click Pin
Saidrex10-Jun-12 6:17
Saidrex10-Jun-12 6:17 
AnswerRe: Enable multiple textboxes one by one on button click Pin
Richard Andrew x6410-Jun-12 7:11
professionalRichard Andrew x6410-Jun-12 7:11 
GeneralRe: Enable multiple textboxes one by one on button click Pin
Saidrex10-Jun-12 8:01
Saidrex10-Jun-12 8:01 
AnswerRe: Enable multiple textboxes one by one on button click Pin
DaveyM6910-Jun-12 10:13
professionalDaveyM6910-Jun-12 10:13 
GeneralRe: Enable multiple textboxes one by one on button click Pin
Saidrex10-Jun-12 11:37
Saidrex10-Jun-12 11:37 
GeneralRe: Enable multiple textboxes one by one on button click Pin
BobJanova10-Jun-12 22:50
BobJanova10-Jun-12 22:50 
GeneralRe: Enable multiple textboxes one by one on button click Pin
Saidrex10-Jun-12 23:07
Saidrex10-Jun-12 23:07 
Questionc# Pin
gopalmahadak9-Jun-12 17:34
gopalmahadak9-Jun-12 17:34 
AnswerRe: c# Pin
Richard Andrew x649-Jun-12 17:52
professionalRichard Andrew x649-Jun-12 17:52 
AnswerRe: c# Pin
PIEBALDconsult9-Jun-12 19:43
mvePIEBALDconsult9-Jun-12 19:43 
AnswerRe: c# Pin
OriginalGriff9-Jun-12 20:10
mveOriginalGriff9-Jun-12 20:10 
GeneralRe: c# Pin
glennPattonWork310-Jun-12 22:20
professionalglennPattonWork310-Jun-12 22:20 
AnswerRe: c# Pin
Dave Kreskowiak10-Jun-12 4:32
mveDave Kreskowiak10-Jun-12 4:32 
GeneralRe: c# Pin
egenis10-Jun-12 5:23
egenis10-Jun-12 5:23 
GeneralRe: c# Pin
Dave Kreskowiak10-Jun-12 6:59
mveDave Kreskowiak10-Jun-12 6:59 
AnswerRe: c# Pin
Abhinav S10-Jun-12 17:18
Abhinav S10-Jun-12 17:18 
Questionpaint event not called Pin
Danzy839-Jun-12 8:19
Danzy839-Jun-12 8:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.