这是有效的卷曲
curl -H“X-Auth-User:bryan”-H“X-Auth-Expires:1406916006”-H“X-Auth-Key:47ec7f890ef9fb2367c44b9dedcc2526”--ciphers“MD5”“ - H”“接受: application / xml“” - H“”Content-Type:application / xml“” - d“”@ c:/projects/elemental/Job3.xml“”https://acb7b192c688.technologies.com/api/jobs“
这是没有返回的C# 在执行用户定义的例程或聚合“ElementalPostRequest”期间发生.NET Framework错误: System.Net.WebException:远程服务器返回错误:(422)Unprocessable Entity。 System.Net.WebException:at System.Net.HttpWebRequest.GetResponse()
不确定我错过了什么。
布赖恩
public static void ElementalPostRequest(String url, String md5url, String elementalUser, String elementalApiKey, Xml XMLInput)
{
TimeSpan t = (DateTime.UtcNow.AddSeconds(30) - new DateTime(1970, 1, 1));
int timestamp = (int)t.TotalSeconds;
string hash = CalculateMD5Hash(elementalApiKey + (CalculateMD5Hash(md5url + elementalUser + elementalApiKey + Convert.ToString(timestamp))));
byte[] data = Encoding.ASCII.GetBytes(Convert.ToString(XMLInput));
var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
httpWebRequest.ContentType = "application/xml";
httpWebRequest.Accept = "application/xml";
httpWebRequest.Method = "POST";
httpWebRequest.Headers.Add("X-Auth-User: " + elementalUser);
httpWebRequest.Headers.Add("X-Auth-Expires: " +Convert.ToString(timestamp));
httpWebRequest.Headers.Add("X-Auth-Key: " + hash);
httpWebRequest.ContentLength = data.Length;
using (Stream stream = httpWebRequest.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
WebResponse response = httpWebRequest.GetResponse();
Stream dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string serverResponse = reader.ReadToEnd();
reader.Close();
dataStream.Close();
response.Close();
}