我正在集成将使用HTTP-POST来请求和检索数据的Web服务.远程服务器需要根据RFC 2617进行基本身份验证
我的身份验证尝试失败了.
它失败了,即使我将'NetworkCredential'对象附加到'HttpWebRequest'对象的'Credentials'属性,也不会在标头中发送验证信息,即使我设置'PreAuthenticate'= true.
我错过了什么?
//使用了块
NetworkCredential netCredential = new NetworkCredential(" uid", "pwd");
Uri uri = new Uri("http://address of services");
ICredentials credentials = netCredential.GetCredential(uri, "Basic");
objRegistration.Credentials = credentials;
objRegistration.PreAuthenticate = true;
Run Code Online (Sandbox Code Playgroud) 除此之外,Powershell 2.0 没有有用的 cmdlet Invoke-RestMethod。
我无法升级到版本 3,我发现的大多数示例都使用版本 3。
我发现这篇文章,但是对于我的简单场景来说似乎太复杂了。
我需要编写一个以 Json 格式发布数据的 Powershell 脚本,例如
{"Id":5,"Email":"test@com","DataFields":null,"Status":0}
Run Code Online (Sandbox Code Playgroud)
我能够获取数据。这是我尝试过的脚本之一。
curl -v --user username:password https://api.dotmailer.com/v2/account-info
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试 POST 时,我不知道将消息正文放在脚本中的何处。这是我到目前为止所得到的:
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":"Could not parse the body of the request based on the content type \"application/json\" ERROR_BODY_DOES_NOT_MATCH_CONTENT_TYPE"}*
谁能就如何使用 cURL 从 Powershell 发布 Json 数据提出建议?
任何有关为什么我会收到我在 Waht 我尝试过的部分中提到的错误的指示,将不胜感激。
谢谢。