Copy Code code as follows:
void Updatecontactsign ()
{
String serverpage = "Http://localhost/WebService/MyService.asmx";
Try
{
Serverpage = "Op=tangramaction";
Serverpage + = "/myaction";//myaction is the method in WebService
String strxml= "<a objid=\" 9\ "></a>",;//First parameter
String Strdata= "contactsign|990011| my Data";//second parameter
string res = Httpconnecttoserver (serverpage, Strxml, strdata);
MessageBox.Show (RES);
}
catch (Exception ex)
{
}
}
Send Message to Server
public string Httpconnecttoserver (string serverpage,string strxml,string strdata)
{
String postdata = "strxml=" + strxml+ "&strdata=" +strdata;
byte[] DataArray = Encoding.Default.GetBytes (postdata);
Create a request
HttpWebRequest request = (HttpWebRequest) httpwebrequest.create (serverpage);
Request. method = "POST";
Request. ContentLength = Dataarray.length;
Request. ContentType = "application/x-www-form-urlencoded";
Create an input stream
Stream dataStream = null;
Try
{
DataStream = Request. GetRequestStream ();
}
catch (Exception)
{
Return null;//Connection Server failed
}
Send Request
Datastream.write (DataArray, 0, dataarray.length);
Datastream.close ();
Read return message
string res = string. Empty;
Try
{
HttpWebResponse response = (HttpWebResponse) request. GetResponse ();
StreamReader reader = new StreamReader (response. GetResponseStream (), Encoding.UTF8);
res = reader. ReadToEnd ();
Reader. Close ();
}
catch (Exception ex)
{
Return null;//Connection Server failed
}
return res;
}