4

I am trying to access a sharepoint server REST api to upload some files. Access is via our tomcat application

Although I believe I setup correctly the headers in IIS the request does not pass the preflight.

Here are the request headers:

Request OPTIONS /_api/contextinfo HTTP/1.1
Accept  */*
Origin  http://localhost:8080
Access-Control-Request-Method   POST
Access-Control-Request-Headers  content-type, accept
Accept-Encoding gzip, deflate
User-Agent  Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; MAAU; rv:11.0) like Gecko
Host    temp-sharepoint
Content-Length  0
Connection  Keep-Alive
Cache-Control   no-cache

and the response headers:

Response    HTTP/1.1 401 Unauthorized
Content-Type    text/plain; charset=utf-8
Server  Microsoft-IIS/7.5
SPRequestGuid   8d690d9d-d06e-101d-6038-8056a7fce7c2
request-id  8d690d9d-d06e-101d-6038-8056a7fce7c2
X-FRAME-OPTIONS SAMEORIGIN
SPRequestDuration   5
SPIisLatency    1
WWW-Authenticate    Negotiate
WWW-Authenticate    NTLM
X-Powered-By    ASP.NET
MicrosoftSharePointTeamServices 15.0.0.4569
X-Content-Type-Options  nosniff
X-MS-InvokeApp  1; RequireReadOnly
Access-Control-Allow-Origin *
Access-Control-Allow-Credentials    true
Access-Control-Allow-Methods    GET,PUT,POST,DELETE,OPTIONS
Access-Control-Allow-Headers    accept,content-type
Date    Fri, 05 Jun 2015 15:52:01 GMT
Content-Length  16

My code to request

var url = sharepointURL + "/_api/contextinfo";
jQuery.ajax({
     url: url,
     type: "POST",
     headers: 
     {
        "Accept": "application/json; odata=verbose"
     },
     xhrFields: {
            withCredentials: true
    },
    crossDomain: true,
     contentType: "application/json;odata=verbose",

Why is not passing the preflight? have I misconfigured the headers?

  • 1
    Does anyone know if there is a problem with preflight OPTIONS requests to IIS? the server is to windows Authentication. Do I need to write a custom module to handle OPTIONS otherwise they will always fail? – user42999 Jun 5 '15 at 18:23
0

For a post you will need to add X-RequestDigest: $("#__REQUESTDIGEST").val() in the header.

  • 1
    Thanks for the answer. Unfortunately it didnt help. Still receiving the same error response and the request never passes preflight – user42999 Jun 5 '15 at 17:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.