Paypal nvp api - 发布请求不起作用

发布于 2024-11-08 00:23:50 字数 778 浏览 3 评论 0原文

我一直在阅读 API 并查看示例,他们似乎使用 POST 来发送请求。当我尝试使用 POST 时,我不断收到 10001 错误。当我将请求方法切换为 GET 时,它就起作用了。

我使用以下代码来发布请求 - 失败

        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
        req.Method = "Post";
        req.ContentType = "application/x-www-form-urlencoded";
        WebResponse response = req.GetResponse();

我使用完全相同的代码来使用 GET,但方法类型除外 - 有效

        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
        req.Method = "Get";
        req.ContentType = "application/x-www-form-urlencoded";
        WebResponse response = req.GetResponse();

我可以使用 GET 来发出 API 请求吗?我之所以问这个问题,是因为网上的每个示例都使用 POST,并且在他们的 API 示例中也使用了 POST。即使发送到 ssl 链接,使用 GET 是否存在某种安全风险?

最后,为什么 POST 请求发回无效响应?

I've been reading through the API and looking at samples and they seem to use POST to send their request. When I tried using POST I kept getting back a 10001 error. When I switched the request method to GET it works.

I was using the following code for Posting the request - FAILS

        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
        req.Method = "Post";
        req.ContentType = "application/x-www-form-urlencoded";
        WebResponse response = req.GetResponse();

I use the exact same code for using GET, except for method type - WORKS

        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
        req.Method = "Get";
        req.ContentType = "application/x-www-form-urlencoded";
        WebResponse response = req.GetResponse();

Can I use GET for making API requests? The reason I ask is because every single example on the net uses POST, and it is used in their API examples as well. Is there some sort of security risk of using GET even though it is sent to an ssl link?

Lastly, why is the POST request sending back an invalid response?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文