How to make a HTTP POSTrequest to an API using headers(如何使用标头向 API 发出 HTTP POST 请求)
问题描述
我需要将 API 集成到我的应用中.文档说:
I need to integrate an API into my app. The docs say:
HTTP POST以下是一个示例 HTTP POST 请求和响应.显示的占位符需要替换为实际值.
响应是:
阅读我在 Laravel Controller 中创建此功能的文档:
Reading the docs I create this function in Laravel Controller:
但我收到了一条消息:
RequestException.php 第 111 行中的 ServerException:服务器错误:POSThttp://stage.example.co.uk/partnerhubwebservice.asmx/Authorise
导致 500 Internal Server Error
响应:缺少参数:用户名.
ServerException in RequestException.php line 111: Server error:
POST http://stage.example.co.uk/partnerhubwebservice.asmx/Authorise
resulted in a500 Internal Server Error
response: Missing parameter: username.
当我在 POSTMAN 应用程序上尝试这个时,一切都很好,我得到了响应:
When I try this at POSTMAN app everything is fine and there I get response ike:
请帮我解决这个问题?我的代码有什么问题?为什么我收到错误消息,并且 POSTMAN 请求工作正常...
Please help me to solve this problem? What is wrong with my code? WHy I got the error , and POSTMAN request works fine ...
推荐答案
尝试在正文中以 body
或 json
形式发送用户名和密码,而不是 >application/x-www-form-urlencoded
,像这样:
Try sending username and password inside of a body as body
or json
, instead of as application/x-www-form-urlencoded
, like so:
或
这篇关于如何使用标头向 API 发出 HTTP POST 请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!