我正在使用F#库HttpFs.Client进行API测试。我知道我做错了事情,没有在标题中设置正确的内容类型,但我不知道如何设置它。
[]设Play with Rest API() =
let request = Request.createUrl Post "https://c2c-lms-qa.ninja24.in/login"
|> Request.setHeader (Accept "application/json")
|> Request.bodyString ReadFile //Reading content of json body
|> Request.responseAsString
|> run
printfn "Here's the Response is : %s" request在这种情况下,我一直收到一个错误:{“代码”:“415”,“消息”:“内容类型'‘不支持’,”错误“:{”字段“:空,”消息“:”内容类型'‘不支持“,”rejectedValue“:null}这里的响应是:{”代码“:”415“,”消息“:”内容类型'’不受支持“,”错误“:{”字段“:空,”消息“:”内容类型'‘不支持’,“,“rejectedValue”:null}
我尝试了各种其他方法,比如绕过这些: a) |> Request.setHeader (ContentType "application/json")
显示一个错误:这个表达式应该有'ContentType‘类型,但是这里有类型'string’或
( b) |> Request.setHeader (自定义(“内容-类型”、“应用程序/json”))
System.Exception :作业引发的异常-> System.InvalidOperationException :被滥用的标头名称。确保请求头与HttpRequestMessage一起使用,响应标头与HttpResponseMessage一起使用,内容标头与HttpContent objects.Result消息一起使用:
JSON正文:{ "idToken":idToken "type":"GOOGLE_LOGIN“}
注*正如建议的那样,我尝试删除内容类型param本身,例如:
设Play with Rest API() =
"Body File content:%s“ReadFile
让请求= Request.createUrl Post“https://c2c-lms-qa.ninja24.in/login” |> Request.bodyString ReadFile
|> Request.responseAsString
|> run
“这里的响应是:%s”请求
但是我仍然收到这个错误:这里的响应是:{“代码”:“415”,“消息”:“内容类型'‘不受支持”,“错误”:{“字段”:空,“消息”:“内容类型'’不支持”,“rejectedValue”:null}
要在邮递员上复制,可以使用以下数据: POST URl:https://c2c-lms-qa.ninja24.in/login Body:https://c2c-lms-qa.ninja24.in/login "type":"GOOGLE_LOGIN"}
由于我已经提供了无效令牌,您将在Postman:{“代码”:"401“、”消息“:”无效令牌“、”错误“:{”字段“:null、”消息“:”无效令牌“、"rejectedValue":null }中看到预期的响应。
但是在F#库HttpFs.Client上,我得到了以下内容:{“代码”:“415”,“消息”:“内容类型'‘不受支持”,“错误”:{“字段”:空,“消息”:“内容类型'’不受支持”,“rejectedValue”:null}
发布于 2020-06-11 14:03:35
下面应该能解决这个问题。传递内容类型的语法有点偏僻:
Request.createUrl Post "https://c2c-lms-qa.ninja24.in/login"
|> Request.setHeader (ContentType (ContentType.create("application", "json")))
|> Request.bodyString token //Reading content of json body
|> Request.responseAsString
|> runhttps://stackoverflow.com/questions/62307624
复制相似问题