我正在编写一个与 AppDirect 集成的程序。链接是: http://info.appdirect.com/developers/docs/api_integration/subscription_management
我成功处理了订阅订单、更改和取消事件。现在,我想将计量使用情况发送到 appdirect,并且我按照此页面上的说明进行操作 http://info.appdirect.com/developers/docs/api_integration/subscription_management/metered_usage_api
但是,它总是返回 HTTP/1.1 401 Unauthorized 和一个很长的 html 页面。这是我对 AppDirect 的 HTTP 请求:
POST https://www.appdirect.com/api/integration/v1/billing/usage?oauth_consumer_key=mykey&oauth_nonce=775137&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1422880351&oauth_version=1.0&oauth_signature=q17RzR1KvuxHXvle0Uxrnn16IIA%3d HTTP/1.1
Content-Type: application/xml
Host: www.appdirect.com
Content-Length: 318
Expect: 100-continue
Accept-Encoding: gzip, deflate
Connection: Keep-Alive
<?xml version="1.0" encoding="utf-16"?>
<usage xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<account>
<accountIdentifier>123456</accountIdentifier>
</account>
<item>
<unit>DOCUMENT</unit>
<quantity>10</quantity>
</item>
</usage>
我的程序使用MVC5、CookieAwareWebClient发送http请求 (代码:How do I log into a site with WebClient?)
我的请求有什么问题吗?如果您需要更多信息,请告诉我。任何帮助将不胜感激。非常感谢。
最佳答案
我知道发生了什么了。这是错误的 OAuth 签名计算。 OAuth 计算中包含的 HTTP 方法是 GET,但它应该是 POST。
一旦我将其更改为 POST,它就可以工作。
关于c# - 如何将计量使用情况发送到 AppDirect,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28278225/