简体   繁体   English

Sharepoint在线API返回:HTTP错误400。请求标头字段太长

[英]Sharepoint online API returns: HTTP Error 400. A request header field is too long

I have a loop that will loop through records in my DB, pulling information i need and then creating 3 folders & upload a file. 我有一个循环,它将循环遍历数据库中的记录,提取所需的信息,然后创建3个文件夹并上传文件。

This works OK for like 40 records but then it starts erroring out with the below response back from sharepoint: <!DOCTYPE HTML PUBLIC \\"-//W3C//DTD HTML 4.01//EN\\"\\"http://www.w3.org/TR/html4/strict.dtd\\">\\r\\n<HTML><HEAD><TITLE>Bad Request</TITLE>\\r\\n<META HTTP-EQUIV=\\"Content-Type\\" Content=\\"text/html; charset=us-ascii\\"></HEAD>\\r\\n<BODY><h2>Bad Request - Header Field Too Long</h2>\\r\\n<hr><p>HTTP Error 400. A request header field is too long.</p>\\r\\n</BODY></HTML> 对于大约40条记录,此操作正常,但随后从共享点返回以下响应开始出错: <!DOCTYPE HTML PUBLIC \\"-//W3C//DTD HTML 4.01//EN\\"\\"http://www.w3.org/TR/html4/strict.dtd\\">\\r\\n<HTML><HEAD><TITLE>Bad Request</TITLE>\\r\\n<META HTTP-EQUIV=\\"Content-Type\\" Content=\\"text/html; charset=us-ascii\\"></HEAD>\\r\\n<BODY><h2>Bad Request - Header Field Too Long</h2>\\r\\n<hr><p>HTTP Error 400. A request header field is too long.</p>\\r\\n</BODY></HTML>

I am not sure whats going on, i read online its todo with cookies but i am using HTTPClient to send the request so i dont know how that would effect it? 我不确定发生了什么,我在线阅读了它的cookie待办事项,但是我正在使用HTTPClient发送请求,所以我不知道这会如何影响它? I also seen onlne about changing the kestrel? 我还看到过关于改变茶est的信息吗?

Can anybody shed some light on this for me? 有人可以帮我一下吗? Provide me with an easy but working solution? 为我提供一个简单但可行的解决方案? I dont use CSOM for integrating to sharepoint online, i use HTTP Requests, below is a sample of how i interact with sharepoint. 我不使用CSOM集成到在线共享点,我使用HTTP请求,以下是我如何与共享点交互的示例。

It seems as if i get blocked or banned temporarily cause if i wait a good bit, i can then make the same request that failed previously, and it will work! 好像我暂时被阻止或禁止,如果我稍等片刻,那么我可以发出先前失败的相同请求,它将起作用! So strange. 这么奇怪。

Sample code (Used to create a resource at Sharepoint): 示例代码(用于在Sharepoint创建资源):

//Set Endpoint
var sharePointEndpoint = $"https://{hostname}/sites/{site}/_api/web/folders";

//Set default headers
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", sharePointToken); //Set token
client.DefaultRequestHeaders.Add("Accept", "application/json;odata=verbose");

//Pre-Body data setup
var metaData = new MetaDataModel();
metaData.type = "SP.Folder";

//Body data setup
var bodyModel = new ExpandoObject() as IDictionary<string, object>;
bodyModel.Add("__metadata", metaData);
bodyModel.Add("ServerRelativeUrl", location + "/" + directoryName + "/");

//Set content headers
HttpContent strContent = new StringContent(JsonConvert.SerializeObject(bodyModel));
strContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
strContent.Headers.ContentType.Parameters.Add(new NameValueHeaderValue("odata", "verbose"));

// Send request, grab response
var response = await client.PostAsync(sharePointEndpoint, strContent);

//Return response message
return response;

It turns out I needed to use Content-Length header when sending the request, once done I was able to successfully communicate with sharepoint without encountering this error. 事实证明,发送请求时我需要使用Content-Length标头,一旦完成,我就能够成功与sharepoint通信而不会遇到此错误。

More information here: https://social.technet.microsoft.com/Forums/en-US/26459f1c-945d-4112-9200-69c5a33a37ff/sharepoint-online-rest-api-returns-http-error-400-a-request-header-field-is-too-long?forum=sharepointdevelopment 此处的更多信息: https : //social.technet.microsoft.com/Forums/zh-CN/26459f1c-945d-4112-9200-69c5a33a37ff/sharepoint-online-rest-api-returns-http-error-400-a-请求标头字段太长?forum = sharepointdevelopment

Thanks. 谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 HTTP 400。请求头的大小太长 - HTTP 400. The size of the request headers is too long 如何修复来自 Azure 云服务的“HTTP 错误 400。请求标头的大小太长”错误? - How to fix "HTTP Error 400. The size of the request headers is too long" error from azure cloud services? IIS 8错误请求400。请求太长 - IIS 8 Bad Request 400. request too long webapi odata-长网址导致“ HTTP错误400。请求网址无效” - webapi odata - long url causes “HTTP Error 400. The request URL is invalid” 错误请求 - 无效 URL - HTTP 错误 400。请求 URL 无效 - Bad Request - Invalid URL - HTTP Error 400. The request URL is invalid 当连接到wcf服务时,为什么会看到“HTTP错误400.请求主机名无效。” - Why do I see “HTTP Error 400. The request hostname is invalid.” when connected to a wcf service gandi api 从 C# 调用返回 400。它的工作正常从 Postman - gandi api call from C# returns 400. Its Working Fine from Postman HTTP/2 连接错误 (PROTOCOL_ERROR):请求标头太长 - HTTP/2 connection error (PROTOCOL_ERROR): Request headers too long 请求 URL 太长 HTTP 错误 414。请求 URL 太长 - Request URL Too Long HTTP Error 414. The request URL is too long HTTP错误414。使用ActionLink的请求URL太长 - HTTP Error 414. The request URL is too long using ActionLink
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM