我正在查看用于传输数据的Stream示例,我想传递一个额外的字符串'infoAsString'
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)
{
请告知....感谢任何回复
答案 0 :(得分:1)
您可以使用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();
}