[英]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.