Sending a string to a PHP page and having the PHP Page Display The String

后端 未结 2 601
广开言路
广开言路 2021-01-23 05:03

What I\'m trying to do is have my PHP page display a string that I\'ve created through a function in my C# application, via System.Net.WebClient.

That\'s really it. In i

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-23 05:05

    Use This Codes To Send String From C# With Post Method

           try
           {
                string url = "";
                string str = "test";
                HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
                req.Method = "POST";
                string Data = "message="+str;
                byte[] postBytes = Encoding.ASCII.GetBytes(Data);
                req.ContentType = "application/x-www-form-urlencoded";
                req.ContentLength = postBytes.Length;
                Stream requestStream = req.GetRequestStream();
                requestStream.Write(postBytes, 0, postBytes.Length);
                requestStream.Close();
    
                HttpWebResponse response = (HttpWebResponse)req.GetResponse();
                Stream resStream = response.GetResponseStream();
    
                var sr = new StreamReader(response.GetResponseStream());
                string responseText = sr.ReadToEnd();
    
    
            }
            catch (WebException)
            {
    
                MessageBox.Show("Please Check Your Internet Connection");
            }
    

    and php page

     
    

提交回复
热议问题