我正在使用 eloqua 10。
我需要在 eloqua 中使用 aspx 网页中的 rest api 创建电子邮件。但是我得到了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>amani@suyati.com</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 发布帖子吗?如果可以,您可以分享一个示例代码以从 c# 向 eloqua 发出 POST 请求。任何帮助都是可观的。