使用cURL的Powershell 2.0的POST请求 [英] POST request with Powershell 2.0 using cURL

查看:456
本文介绍了使用cURL的Powershell 2.0的POST请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在其他方面,Powershell 2.0没有有用的cmdlet Invoke-RestMethod。

Among other things, Powershell 2.0 doesn't have the useful cmdlet Invoke-RestMethod.

我无法升级到版本3,发现大多数示例都使用版本3。

I can't upgrade to version 3 and most examples I've found use version 3.

我发现这篇文章,但是,对于我的简单情况而言,它似乎太复杂了。

I have found this article, which seems, however, too complicated for my simple scenario.

我需要编写一个Powershell脚本,以Json格式发布数据,例如

I need to write a Powershell script that POSTs data in Json format, e.g.

{"Id":5,"Email":"test@com","DataFields":null,"Status":0}



我尝试过的事情



我能够获取数据。这是我尝试过的脚本之一。

What I've tried

I am able to GET data. This is one of the scripts I have tried.

curl -v --user username:password https://api.dotmailer.com/v2/account-info

但是,当我尝试发布时,我无法确定在脚本中放置消息正文的位置。这是到目前为止我得到的:

But, when I try to POST, I can't figure out where to put the body of the message in the script. This is what I've got so far:

curl -v -X POST -H Accept:application / json -H Content -Type:application / json -u username:password -d'{ Id:5, Email: test @ com, OptInType:0, EmailType:0, DataFields:null, Status:0}'https://api.dotmailer.com/v2/contacts

会返回以下错误:

{ message:无法根据内容类型\ application / json\解析请求的正文 ERROR_BODY_DOES_NOT_MATCH_CONTENT_TYPE} *

有人可以建议如何发布

任何指向为什么我得到在我尝试过的次数部分中提到的错误的指针将不胜感激。

Any pointers to why I get the error I mentioned in the Waht I've tried section would be much appreciated.

谢谢。

推荐答案

来自curl的手册页,看来您需要使用 -d 开关:

From curl's man page it appears you need to use -d switch:

curl -v --user username:password -H "Content-Type: application/json" -d '{"Id":5,"Email":"test@com","DataFields":null,"Status":0}' https://api.dotmailer.com/v2/contacts

这篇关于使用cURL的Powershell 2.0的POST请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆