2014-03-25 81 views
1

我正在使用eloqua 10.如何使通过REST API的支撑柱,Eloqua?

我需要在eloqua中使用他们的其余api从aspx网页创建电子邮件。但是我得到404 Bad Request

下面给出的是,我试图POST请求的代码示例。

string authenticateStr = eloquainstance + @"\" + username + ':' + password; 

byte[] bytesToEncode = Encoding.UTF8.GetBytes(authenticateStr); 

string encodedText = Convert.ToBase64String(bytesToEncode); 

string requrl = "/assets/email"; 

string requestBody = "<subject>Test subject</subject>" + 
         "<senderName>Ajai Test</senderName>" + 
         "<senderEmail>[email protected]</senderEmail>" + 
         "<emailGroupId>9</emailGroupId>" + 
         "<htmlContent>This is a test email templete created  trough rest api.This is for testing purpose only</htmlContent>"+ 
         "<type>Email</type>" + 
         "<name>Email By api</name>"; 


HttpWebRequest request = (HttpWebRequest)WebRequest.Create(baseurl + requrl); 
request.Headers.Add("Authorization", "Basic " + encodedText); 
request.Accept = "application/xml";//"application/x-www-form-urlencoded"; 
request.Method = "POST"; 
request.ContentType = "application/xml"; 
request.ContentLength = requestBody.Length; 

//write body to text 
byte[] body = System.Text.Encoding.UTF8.GetBytes(requestBody); 
Stream dataStream = request.GetRequestStream(); 
dataStream.Write(body, 0, requestBody.Length); 
dataStream.Close(); 

HttpWebResponse webResponse = (HttpWebResponse)request.GetResponse(); 

如果在我的代码中有任何错误,请纠正我。

任何人都可以尝试使用eloqua REST API后,如果这样你就可以分享示例代码,使POST请求eloqua从C#。任何帮助是明显的。

回答

0

不知道你是否已经有了这方面的工作还因为既然你问这一段时间已经过去,但你可以找到一整套样品的使用eloqua的topliners网站:

http://topliners.eloqua.com/community/code_it/blog/2012/10/08/eloqua-rest-api--open-source-c-samples

看着您的代码我认为您可能需要转义html身份

我还会考虑编写一个类来表示电子邮件对象,然后使用restsharp来简化序列化请求和处理响应的过程。

与使用招测试请求也进行实验。