Как передать значения в заголовок и раздел PATH PARAMETERS для получения ответа от API, используя класс HttpWebRequest в C #?
HEADER
Авторизация: Носитель
UserId: идентификатор пользователя
ПАРАМЕТРЫ ПУТИ
recid: идентификатор записи
Ниже приведен кодЯ пытался ..
HttpWebRequest MetadataRequest = (HttpWebRequest)WebRequest.Create(metadatarequestUri);
MetadataRequest.ContentType = "multipart/form-data; boundary=" + boundary;
MetadataRequest.Method = "GET";
MetadataRequest.KeepAlive = true;
MetadataRequest.Headers.Add("Authorization", "Bearer " + AccessTokenValue);
var recid = "00482365-91c4-g416d-b8a1-06agfga8bcfe8ee";
var AccessTokenValue = "8a2fyhfgc-43f1-4b9e-b64a-dca79grdgedr75642";
var userId = "ka.san";
var metadatarequestUri="https://webserverdev.demovision.com:8493/demoecmv2/rest/docs/" + recid + "/attachments";
Stream memStream2 = new System.IO.MemoryStream();
if (formFields != null)
{
foreach (string key in formFields.Keys)
{
string formitem = string.Format(formdataTemplate, key, formFields[key]);
byte[] formitembytes = System.Text.Encoding.UTF8.GetBytes(formitem);
memStream2.Write(formitembytes, 0, formitembytes.Length);
}
}
memStream2.Write(endBoundaryBytes, 0, endBoundaryBytes.Length);
MetadataRequest.ContentLength = memStream2.Length;
using (Stream requestStream = MetadataRequest.GetRequestStream())
{
memStream2.Position = 0;
byte[] tempBuffer = new byte[memStream2.Length];
memStream2.Read(tempBuffer, 0, tempBuffer.Length);
memStream2.Close();
requestStream.Write(tempBuffer, 0, tempBuffer.Length);
}
memStream2.Write(endBoundaryBytes, 0, endBoundaryBytes.Length);
MetadataRequest.ContentLength = memStream2.Length;
using (Stream requestStream = MetadataRequest.GetRequestStream())
{
memStream2.Position = 0;
byte[] tempBuffer = new byte[memStream2.Length];
memStream2.Read(tempBuffer, 0, tempBuffer.Length);
memStream2.Close();
requestStream.Write(tempBuffer, 0, tempBuffer.Length);
}
using (var response = MetadataRequest.GetResponse())
{
Stream stream2 = response.GetResponseStream();
StreamReader reader2 = new StreamReader(stream2);
var uploadedFileResponseFromAltusECM = reader2.ReadToEnd();
dynamic obj = JsonConvert.DeserializeObject(uploadedFileResponseFromAltusECM);
recid = obj.messages[0].message;
}
Но он не работает, как ожидалось.