简体   繁体   English

如何在HTTP请求正文中发布此-d

[英]How to POST this -d in the body of HTTP request

This is probably an easy question, but I haven't found a super clear answer. 这可能是一个简单的问题,但是我还没有找到一个非常明确的答案。

I basically want to convert this curl POST request: 我基本上想转换此curl POST请求:

curl https://api.leaddyno.com/v1/affiliates \
         -d key=[YOUR_PRIVATE_KEY] \
         -d email=example@example.com

to an API call in Apps Scripts (I think this question goes across all languages though). 到Apps脚本中的API调用(尽管我认为此问题涉及所有语言)。

I found I could just add the -d parameters as query parameters to the end of the request, but I can't seem to pass them in the body. 我发现我可以将-d参数作为查询参数添加到请求的末尾,但似乎无法在正文中传递它们。 When passing JSON I just use JSON.stringify on a javascript object and it works great. 传递JSON时,我只在javascript对象上使用JSON.stringify,效果很好。 So I guess my question is how do I format this so it has the same effect as when I make the data a query string? 所以我想我的问题是如何格式化它,使其与将数据设为查询字符串时具有相同的效果?

This works great: https://api.leaddyno.com/v1/affiliates?key=xxxxx&email=aaa@example.com 这很好用: https://api.leaddyno.com/v1/affiliates?key=xxxxx&email=aaa@example.com : https://api.leaddyno.com/v1/affiliates?key=xxxxx&email=aaa@example.com

Thanks in advance. 提前致谢。

Data to be sent in the post body is added to the payload property of the options object you pass to UrlfetchApp. 将在帖子正文中发送的数据添加到您传递给UrlfetchApp的options对象的有效负载属性中。

var payload = {key:1233456,email:"bob@abc.edu"};
var options = {method:"POST", contentType:"application/json", payload:JSON.stringify(payload)};
var URL =" https://api.leaddyno.com/v1/affiliates";
var results = UrlfetchApp.fetch(URL,options);

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

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