我想发送一个POST请求到一个指定的Endpoint。为了授权,我必须在请求头设置一个 "x-api-key: key-value pair"。
这就是我正在使用的方法。
public string postXMLData(string destinationUrl, string requestXml)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(destinationUrl);
byte[] bytes;
bytes = System.Text.Encoding.ASCII.GetBytes(requestXml);
request.ContentType = "text/xml; encoding='utf-8'";
request.ContentLength = bytes.Length;
request.Method = "POST";
...
你只需要添加
request.Headers.Add("x-api-key", "the secret key");
其中 "the secret key"
是您的API密钥。