Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

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

$
0
0
I have a loop that will loop through records in my DB, pulling information i need and then creating 3 folders & upload a file.

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>`

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? I also seen onlne about changing the kestrel?

Can anybody shed some light on this for me? Provide me with an easy but working solution? I dont use CSOM for integrating as there is no support for .net core, i use HTTP Requests, below is a sample of how i interact with sharepoint.

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):

    //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;

Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>