我正在尝试调用发布请求以将文件上传到 Archer。请在下面找到我的代码:
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
data = open('testdoc.txt','rb').read()
url = "http://rsaarcher/platformapi/core/content/attachment" #my archer url
token = "<my session id token>"
headers = {
'Accept':'application/json,text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Authorization': 'Archer session-id="'+token+'"',
'content-type': "application/json;",
'cache-control': "no-cache",
}
response = requests.request("POST", url, data=data, headers=headers, verify = False)
print(response.content)
print(response.status_code)
我收到以下错误:b'{"Message":"请求包含实体主体但没有 Content-Type 标头。此资源不支持推断的媒体类型 \'application/octet-stream\'。", "ExceptionMessage":"没有 MediaTypeFormatter 可用于从媒体类型为 \'application/octet-stream\' 的内容中读取类型为 \'AttachmentWrapper\' 的对象。","ExceptionType":"System.Net.Http.UnsupportedMediaTypeException" “StackTrace”:“在 System.Net.Http.HttpContentExtensions.ReadAsAsync[T](HttpContent 内容,类型类型,IEnumerable 1 formatters, IFormatterLogger formatterLogger, CancellationToken cancellationToken)\\r\\n at System.Web.Http.ModelBinding.FormatterParameterBinding.ReadContentAsync(HttpRequestMessage request, Type type, IEnumerable
1 格式化程序,IFormatterLogger 格式化程序记录器,CancellationToken 取消令牌)”}'状态码:415