In the HTTP protocol, the following parameters are transmitted to the server: HTTP header/get String/post body
The following example Code Demonstrate how to simply post data to the server.
// Send request
String Requestbody = String . Format ( " {0 }={ 1} & {2 }={ 3} & {4 }={ 5} & {6 }={ 7} & {8 }={ 9} "
, Httputility. urlencode ( " Version_id " , Encoding. getencoding ( " Gb2312 " ))
, Httputility. urlencode (m_versionno, encoding. getencoding ( " Gb2312 " ))
, Httputility. urlencode ( " Merchant_id " , Encoding. getencoding ( " Gb2312 " ))
, Httputility. urlencode (m_merchantid, encoding. getencoding ( " Gb2312 " ))
, Httputility. urlencode ( " Verifystring " , Encoding. getencoding ( " Gb2312 " ))
, Httputility. urlencode (hashstr. tostring (). tolower (), encoding. getencoding ( " Gb2312 " ))
, Httputility. urlencode ( " Order_date " , Encoding. getencoding ( " Gb2312 " ))
, Httputility. urlencode (m_orderdate, encoding. getencoding ( " Gb2312 " ))
, Httputility. urlencode ( " Order_id " , Encoding. getencoding ( " Gb2312 " ))
, Httputility. urlencode (m_orderid, encoding. getencoding ( " Gb2312 " ))
, Httputility. urlencode ( " Retmode " , Encoding. getencoding ( " Gb2312 " ))
, String . Empty
);
Httpwebrequest request = (Httpwebrequest) httpwebrequest. Create (m_gatewayurl );
Request. Method = " Post " ;
Request. keepalive = False ;
Request. contenttype = " Application/X-WWW-form-urlencoded " ;
Byte [] Arybuf = Encoding. getencoding ( " Gb2312 " ). Getbytes (requestbody );
Request. contentlength = Arybuf. length;
Using (Stream writer = Request. getrequeststream ())
{
Writer. Write (arybuf,0, Arybuf. Length );
Writer. Close ();
Writer. Dispose ();
}
String RET = String . Empty;
Using (Webresponse response = Request. getresponse ())
{
Streamreader= NewStreamreader (response. getresponsestream ()
, Encoding. getencoding ("Gb2312")
);
RET=Reader. readtoend ();
Reader. Close ();
Reader. Dispose ();
}