【发布时间】:2020-08-12 11:21:42
【问题描述】:
我有一个通过调用 REST API 创建 Azure DevOps 项目的管理脚本。只要名称或描述参数不包含特殊字符,它就可以正常工作。例如,如果描述中有德语变音符号,则调用失败。
这行得通:
curl -k -D- -X POST -d '{"name":"Phantom","capabilities":{"processTemplate":{"templateTypeId":"6b724908-ef14-45cf-84f8-768b5384da45"},"versioncontrol":{"sourceControlType":"Git"}},"visibility":"private","description":"Innocent description without umlauts"}' -H 'Accept: application/json' -H 'Content-Type: application/json' -H 'Authorization: Basic secretauthorizationtoken=' https://dev.azure.com/AdminPlayground/_apis/projects?api-version=6.0-preview.4
这个抛出异常:
curl -k -D- -X POST -d '{"name":"Phantom","capabilities":{"processTemplate":{"templateTypeId":"6b724908-ef14-45cf-84f8-768b5384da45"},"versioncontrol":{"sourceControlType":"Git"}},"visibility":"private","description":"Funny description with strange äöüß chars"}' -H 'Accept: application/json' -H 'Content-Type: application/json' -H 'Authorization: Basic secretauthorizationtoken=' https://dev.azure.com/AdminPlayground/_apis/projects?api-version=6.0-preview.4
例外是:
{"$id":"1","innerException":null,"message":"Value cannot be null.\r\nParameter name: projectToCreate","typeName":"System.ArgumentNullException, mscorlib","typeKey":"ArgumentNullException","errorCode":0,"eventId":0}
有没有人遇到过类似的行为,或许可以提出解决方案? 谢谢!
【问题讨论】:
-
尝试将
charset=utf-8添加到Content-Type,例如'Content-Type: application/json;charset=utf-8' -
我在 Content-Type Header 中尝试了带有 charset=utf-8 的命令 - 结果相同。
标签: rest azure-devops