Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Mar 30, 2012 08:51 AM by oguzkaygun
Member
555 Points
1386 Posts
Mar 30, 2012 07:50 AM|LINK
Hello
Below funtion to send SMS to phont. I couldnt convert it to Csharp. Can you convert it please ? PHP and Csharp codes are below.
function HTTP_POST ($Url,$strRequest) { $ch=curl_init(); curl_setopt($ch, CURLOPT_URL, $Url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1) ; curl_setopt($ch, CURLOPT_POSTFIELDS, $strRequest); curl_setopt($ch, CURLOPT_TIMEOUT, 30); $result = curl_exec($ch); curl_close($ch); return $result; }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; using System.IO; public class MyWebRequest { private WebRequest request; private Stream dataStream; private string status; public String Status { get { return status; } set { status = value; } } public MyWebRequest(string url) { // Create a request using a URL that can receive a post. request = WebRequest.Create(url); } public MyWebRequest(string url, string method) : this(url) { if (method.Equals("GET") || method.Equals("POST")) { request.Method = method; } else { throw new Exception("Invalid Method Type"); } } public MyWebRequest(string url, string method, string data) : this(url, method) { string postData = data; byte[] byteArray = Encoding.UTF8.GetBytes(postData); request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = byteArray.Length; dataStream = request.GetRequestStream(); dataStream.Write(byteArray, 0, byteArray.Length); dataStream.Close(); } public string GetResponse() { WebResponse response = request.GetResponse(); this.Status = ((HttpWebResponse)response).StatusDescription; dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); string responseFromServer = reader.ReadToEnd(); reader.Close(); dataStream.Close(); response.Close(); return responseFromServer; } }
Mar 30, 2012 08:51 AM|LINK
My csharp code works. I just wrote URL and DATA while it didnt work.
oguzkaygun
Member
555 Points
1386 Posts
PHP to CSharp one function ?
Mar 30, 2012 07:50 AM|LINK
Hello
Below funtion to send SMS to phont. I couldnt convert it to Csharp. Can you convert it please ? PHP and Csharp codes are below.
function HTTP_POST ($Url,$strRequest) { $ch=curl_init(); curl_setopt($ch, CURLOPT_URL, $Url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1) ; curl_setopt($ch, CURLOPT_POSTFIELDS, $strRequest); curl_setopt($ch, CURLOPT_TIMEOUT, 30); $result = curl_exec($ch); curl_close($ch); return $result; }using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; using System.IO; public class MyWebRequest { private WebRequest request; private Stream dataStream; private string status; public String Status { get { return status; } set { status = value; } } public MyWebRequest(string url) { // Create a request using a URL that can receive a post. request = WebRequest.Create(url); } public MyWebRequest(string url, string method) : this(url) { if (method.Equals("GET") || method.Equals("POST")) { request.Method = method; } else { throw new Exception("Invalid Method Type"); } } public MyWebRequest(string url, string method, string data) : this(url, method) { string postData = data; byte[] byteArray = Encoding.UTF8.GetBytes(postData); request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = byteArray.Length; dataStream = request.GetRequestStream(); dataStream.Write(byteArray, 0, byteArray.Length); dataStream.Close(); } public string GetResponse() { WebResponse response = request.GetResponse(); this.Status = ((HttpWebResponse)response).StatusDescription; dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); string responseFromServer = reader.ReadToEnd(); reader.Close(); dataStream.Close(); response.Close(); return responseFromServer; } }oguzkaygun
Member
555 Points
1386 Posts
Re: PHP to CSharp one function ?
Mar 30, 2012 08:51 AM|LINK
My csharp code works. I just wrote URL and DATA while it didnt work.