this function will post some data to the server, and then the server will
send back some message,
it is works in either winform or webform programs,but not in smart device
programs. what's the problem?
public int GetResponse(ref string OutPut)
{
int iResult = 0;
string SendContain = "";
//Init HttpWebRequest
System.Net.HttpWebRequest myRequest =
(HttpWebRequest)WebRequest.Create(_RequestUrl); // _RequestUrl : post
url
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.Timeout = 10000;
myRequest.Method = "POST";
//build the content what will be sent
for(int i = 0 ; i<_Item.Count;i++)
{
if(SendContain!="")
SendContain += "&";
SendContain += _Item.GetKey(i) + "=" + _Item[i];
}
//input the string into byte[]
byte []PostData = System.Text.Encoding.Default.GetBytes(SendContain);
myRequest.ContentLength = PostData.Length;
//send the data
try
{
myRequest.KeepAlive = true;
System.IO.Stream PostBuffer = myRequest.GetRequestStream();
System.IO.Stream ReceiveBuffer;
System.IO.StreamReader sr;
PostBuffer.Write(PostData,0,PostData.Length);
ReceiveBuffer = myRequest.GetResponse().GetResponseStream(); //here will
raise a error
sr= new StreamReader(ReceiveBuffer,Encoding.Default);
OutPut = sr.ReadToEnd();
}
catch(System.Exception ee)
{
OutPut = ee.Message;
return -6; //cannot connect with server
}
return iResult;
}
thanks