我正在与Spreedly合作,并且遇到了一个小问题。
为了我的一生,我不明白为什么我的代码没有正确发送我的上下文...
这是我的代码(凭据已更改),返回错误(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,所以我缺少一些简单的东西似乎是合理的。
可以将他们的文档保存在这里。
例子不胜枚举,说我应该发送以下内容:
$ curl https://core.spreedly.com/v1/gateways.xml \
-u 'Ll6fAtoVSTyVMlJEmtpoJV8Shw5:RKOCG5D8D3fZxDSg504D0IxU2XD4Io5VXmyzdCtTivHFTTSylzM2ZzTWFwVH4ucG' \
-H 'Content-Type: application/xml' \
-d '<gateway>
<gateway_type>test</gateway_type>
</gateway>'
任何帮助将不胜感激。
谢谢你。
尝试更改以下行:
request.ContentType = "application/xml";
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句