简体   繁体   English

如何通过 API 提交 POST 请求

[英]How to submit POST request via API

I did some searching and haven't come across anything for what I am trying to accomplish.我做了一些搜索,但没有遇到任何我想要完成的事情。 I am trying to apply for a new job and there is an option to apply by API.我正在尝试申请一份新工作,并且可以选择通过 API 申请。 This is new to me so I thought I would give it a try and pick up some learning along the way.这对我来说是新的,所以我想我会尝试一下,并在此过程中学到一些东西。 I have some understanding of front end development but no experience with JSON.我对前端开发有一些了解,但没有使用 JSON 的经验。 The API instructions are quoted as saying "Simply submit a POST request to our careers endpoint with a raw JSON request body, as shown, and we'll get back to you!"引用 API 说明说:“只需使用原始 JSON 请求正文向我们的职业生涯端点提交 POST 请求,如图所示,我们会​​回复您!”

POST https://contact.companyname.com/jobs

{
"name": "Jane Doe",
"email": "jane@hotmail.com",
"resume": "www.linktoresume.com",
"github": "github.com/jane", // optional
"twitter": "@jane", // optional
"website": "jane.com" // optional
}

For someone without any understanding of where to even start with this, is there a write up on how to start or accomplish this?对于甚至不知道从哪里开始的人,是否有关于如何开始或完成此操作的文章?

To send an API request you need to use a REST client.要发送 API 请求,您需要使用 REST 客户端。 A popular client is Postman , they have a lot of great documentation which makes it easy to use.一个受欢迎的客户是Postman ,他们有很多很棒的文档,这使得它易于使用。

Also, another method which might be easier is to use curl to send the request.此外,另一种可能更简单的方法是使用 curl 发送请求。 Curl is used on the command line in your terminal. Curl 用于终端的命令行。 It comes pre-installed on Linux and MacOS or can be downloaded.它预装在 Linux 和 MacOS 上,也可以下载。

Once you have curl you can send your request like this:一旦你有了 curl,你就可以像这样发送你的请求:

curl -d '{"name":"Jane Doe", "email": "jane@hotmail.com", "resume": "www.linktoresume.com", "github": "github.com/jane", "twitter": "@jane", "website": "jane.com"}' -H "Content-Type: application/json" -X POST https://contact.companyname.com/jobs

有很多clients使用它们发送http请求。我建议安装Postman并使用http Post方法发出请求。当然,当您选择 Post 方法时,您可以将此json粘贴为raw body 下。不要忘记将文本更改为application/json

If you're using Windows you may want to check out this post for alternate syntax. 如果您使用的是Windows,则可能需要查看这篇文章以了解其他语法。 This was the correct answer for me, but I needed slightly different formatting to make it work for Windows. 这对我来说是正确的答案,但是我需要略有不同的格式才能使其在Windows上运行。 cURL POST command line on WINDOWS RESTful service WINDOWS RESTful服务上的cURL POST命令行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM