我正在努力将 POST 方法用于 RESTful 服务。我的要求是我需要附加一些参数(不在 URL 中)和我需要从文件中读取的 2 个参数。该服务是用 Java 编写的。
string url= "http://srfmdpimd2:18109/1010-SF-TNTIN/Configurator/rest/importConfiguration/"
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
FileStream file = new FileStream(@"TestSCDS.properties", FileMode.Open);
Byte[] bytes = new Byte[file.Length];
file.Read(bytes, 0, bytes.Length);
string strresponse = Encoding.UTF8.GetString(bytes);
request.Method = "POST";
request.ContentType = "multipart/form-data;";
request.ContentLength = file.Length;
request.Headers.Add("hhrr", "H010");
request.Headers.Add("env", "TEST");
request.Headers.Add("buildLabel", "TNTAL_05.05.0500_C54");
Stream Postdata = request.GetRequestStream();
Postdata.Write(bytes, 0, bytes.Length);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();`
request.Headers.Add()
正在向 URL 添加参数?如果没有,如何在 RESTful 服务中向 POST 方法发送多个参数?
另外,如何从文件中读取参数并在 POST 方法中使用?