This is the curl that works
curl -H "X-Auth-User: bryan" -H "X-Auth-Expires: 1406916006" -H "X-Auth-Key: 47ec7f890ef9fb2367c44b9dedcc2526" --ciphers "MD5" "-H" "Accept: application/xml" "-H" "Content-Type: application/xml" "-d" "@c:/projects/elemental/Job3.xml" "http://ift.tt/XrsANI"
This is the C# that doesn't it returns A .NET Framework error occurred during execution of user-defined routine or aggregate "ElementalPostRequest": System.Net.WebException: The remote server returned an error: (422) Unprocessable Entity. System.Net.WebException: at System.Net.HttpWebRequest.GetResponse()
Not sure what I have missed.
Bryan
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();
}
No comments:
Post a Comment