我正在查看用于传输数据的流的示例
string infoAsString = "blablabla";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
byte[] requestBytes = System.Text.Encoding.ASCII.GetBytes(message);
request.Method = "POST";
request.ContentType = "text/xml;charset=utf-8";
request.ContentLength = requestBytes.Length;
using (Stream requestStream = request.GetRequestStream())
{
//pass infoAsString?
requestStream.Write(requestBytes, 0, requestBytes.Length);
requestStream.Close();
}
//然后我可以抓住它..
public object Upload(string infoAsString)
{
请建议....谢谢您的任何答复
您可以使用request.Headers
集合:
string infoAsString = "blablabla";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
byte[] requestBytes = System.Text.Encoding.ASCII.GetBytes(message);
request.Method = "POST";
request.ContentType = "text/xml;charset=utf-8";
request.ContentLength = requestBytes.Length;
request.Headers.Add(string.format("infoAsString: {0}", infoAsString))
using (Stream requestStream = request.GetRequestStream())
{
requestStream.Write(requestBytes, 0, requestBytes.Length);
requestStream.Close();
}