あなたが提供したコードに基づいて、私は自分の側でテストし、この問題を再現しました。コードをデバッグすると、次のような詳細なエラーを見つけることができます。

私の知る限り、一部の一般的なヘッダーは制限されていると見なされ、システムによって保護されており、WebHeaderCollection
オブジェクトで設定または変更することはできません。このチュートリアルに従うことができます。
簡単な方法として、HttpWebRequest
代わりに使用WebClient
して目的を達成することをお勧めします。RESTful API を使用してプールを作成するためのテスト コードを次に示します。
public static void CreatePoolViaRestAPI(string baseUrl, string batchAccountName, string batchAccountKey,string jsonData)
{
string verb = "POST";
string apiVersion= "2016-07-01.3.1";
string ocpDate= DateTime.UtcNow.ToString("R");
string contentType = "application/json; odata=minimalmetadata; charset=utf-8";
string reqUrl = string.Format("{0}/pools?api-version={1}", baseUrl, apiVersion);
//construct the request
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(reqUrl);
request.Method = verb;
//Set ContentType
request.ContentType = contentType;
//Set ocp-date
request.Headers.Add("ocp-date", ocpDate);
var buffer = Encoding.UTF8.GetBytes(jsonData);
request.ContentLength = buffer.Length;
#region generate the signature
string CanonicalizedHeaders = string.Format("ocp-date:{0}", ocpDate);
string CanonicalizedResource = string.Format("/{0}/pools\napi-version:{1}", batchAccountName, apiVersion);
string stringToSign = string.Format("{0}\n\n\n{1}\n\n{2}\n\n\n\n\n\n\n{3}\n{4}",
verb,
buffer.Length,
contentType,
CanonicalizedHeaders, CanonicalizedResource);
//encode the stringToSign
string signature = EncodeSignStringForSharedKey(stringToSign, batchAccountKey);
#endregion
//Set Authorization header
request.Headers.Add("Authorization", string.Format("SharedKey {0}:{1}", batchAccountName, signature));
using (var rs = request.GetRequestStream())
{
rs.Write(buffer, 0, buffer.Length);
}
//send the request and get response
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
Console.WriteLine("Response status code:{0}", response.StatusCode);
}
}
注: cloudServiceConfiguration プロパティと virtualMachineConfiguration プロパティは相互に排他的であり、指定できるプロパティは 1 つだけです。どちらも指定されていない場合、Batch サービスは Bad Request (400) を返します。したがって、上記の関数の jsonData パラメータは次のようになります。
"{\"id\":\"DotNetPool\",\"vmSize\":\"small\",\"cloudServiceConfiguration\":{\"osFamily\":\"4\"}}"
アップデート:
stringToSign をエンコードするメソッドは次のようになります。
public string EncodeSignStringForSharedKey(string stringToSign, string accountKey)
{
HMACSHA256 h = new HMACSHA256(Convert.FromBase64String(accountKey));
var byteArray = h.ComputeHash(Encoding.UTF8.GetBytes(stringToSign));
string signature = Convert.ToBase64String(byteArray);
return signature;
}
共有キーによる認証に従うことができる詳細。