Question

I want to make a POST request with JSON data to a REST API through the WebProxy. Therefor I make a request like:

$.ajax({
    url: "../_api/SP.WebProxy.invoke",
    type: "POST",
    data: JSON.stringify(
        {
            "requestInfo": {
                "__metadata": { "type": "SP.WebRequestInfo" },
                "Url": someURL,
                "Method": "POST",
                "Headers": {
                    "results": [{
                        "__metadata": { "type": "SP.KeyValue" },
                        "Key": "Accept",
                        "Value": "application/json;odata=verbose",
                        "ValueType": "Edm.String"
                    }]
                },
                "Body": json
            }
        }),
    headers: {
        "Accept": "application/json;odata=verbose",
        "Content-Type": "application/json;odata=verbose",
        "X-RequestDigest": $("#__REQUESTDIGEST").val()
    }
});

Now my Question is where do I have do put my JSON data? The data element of the request seems to be for the request to the webproxy. So I guess I need to send the data within the "inner" request but with the body element it doesn't work.

Était-ce utile?

La solution

Add Content-Type with application/json to the result-array of headers (same as with Accept), like this:

results: [{
    __metadata: {
        type: "SP.KeyValue"
    },
    Key: "Accept",
    Value: "application/json",
    ValueType: "Edm.String"
}, {
    __metadata: {
        type: "SP.KeyValue"
    },
    Key: "Content-Type",
    Value: "application/json",
    ValueType: "Edm.String"
}]
Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange
scroll top