0
我正在与Spreedly合作,而且我正在运行我认为是小问题。使用C#发送WebRequest到Spreedly时出错:(422)无法处理的实体
对于我的生活,为什么我的代码不正确地送我的背景,我不明白...
这是我的代码(凭证已被更改),返回错误(422)处理的实体,我只能假设它意味着正在发送的XML有问题,但是当我设置一个断点时它似乎是正确的。
string url = "https://core.spreedly.com/v1/gateways.xml";
WebRequest request = WebRequest.Create(url);
request.ContentType = "Content-type: application/xml";
request.Method = "POST";
request.Credentials = new NetworkCredential("Ll6fAtoVSTyVMlJEmtpoJV8Shw5", "RKOCG5D8D3fZxDSg504D0IxU2XD4Io5VXmyzdCtTivHFTTSylzM2ZzTWFwVH4ucG");
XElement xelement = new XElement("gateway", new XElement("gateway_type", "test"));
byte[] buffer = Encoding.UTF8.GetBytes(xelement.ToString());
request.ContentLength = buffer.Length;
Stream reqstr = request.GetRequestStream();
reqstr.Write(buffer, 0, buffer.Length);
reqstr.Close();
WebResponse response = request.GetResponse();
我不经常使用WebRequest,因此我错过了一些简单的东西并不合理。
Spreedly保留其文件here。
的例子是卷曲,说我应该发送以下内容:
$ curl https://core.spreedly.com/v1/gateways.xml \
-u 'Ll6fAtoVSTyVMlJEmtpoJV8Shw5:RKOCG5D8D3fZxDSg504D0IxU2XD4Io5VXmyzdCtTivHFTTSylzM2ZzTWFwVH4ucG' \
-H 'Content-Type: application/xml' \
-d '<gateway>
<gateway_type>test</gateway_type>
</gateway>'
任何帮助将不胜感激。
谢谢。
你可能要考虑两个Github上回购之一,而不是重塑在C#中轮:https://github.com/malixsys/Spreedly.Net和https: //github.com/philjones88/SpreedlyCoreSharp都实现了你要查找的大部分功能 – hross