AnsweredAssumed Answered

PI Web API POST Problem (Cors)

Question asked by JensPr on Oct 3, 2016
Latest reply on Nov 22, 2018 by Ashif Sayyad

Hi there,

though I have Pi Web API up and running for GET, it refuses with POST. And I do not get it.

It is not complaining for CORS when doing GET.  Anyone a clue?

 

Here is the configuration:

{
  "AuthenticationMethods": [
  "Anonymous"
  ],
  "CorsExposedHeaders": "Allow,Content-Encoding,Content-Length,Date,Location",
  "CorsHeaders": "accept, authorization, content-type",
  "CorsMethods": "GET,OPTIONS,POST",
  "CorsOrigins": " http://swhars6004.swde2.local, http://plog-sto-01.int.nynas.com",
  "CorsSupportsCredentials": true,
  "DisableWrites": true,
  "SearchBoosts": [
  1.0,
  0.8,
  0.5,
  0.5,
  0.5,
  0.5,
  0.5
  ],
  "SearchPointAttributes": [
  "pointsource",
  "instrumenttag",
  "location1",
  "exdesc"
  ],
  "SearchScanInterval": 180
}

 

Here is the Code:

function postTest() {

  var req = {
   "1": {
     "Method": "GET",
     "Resource": "https://piafhar-sto-01/piwebapi/streamsets/interpolated?webID=P03rCkp0judEazHPxrmYHHRQRx0AAAUElIQVItU1RPLTAxXFRLU1QwMjAxLkdST1NTUVRZ&webID=P03rCkp0judEazHPxrmYHHRQSR0AAAUElIQVItU1RPLTAxXFRLU1QwMjAxLkZSRUVRVFk&webID=P03rCkp0judEazHPxrmYHHRQUx0AAAUElIQVItU1RPLTAxXFRLU1QwMjAxLkxFVkVM&startTime=10/01/2016%2000:00&endTime=10/03/2016%2000:00&interval=15m",
     "Content": "{\"Name\":\"New Element\"}",
     "Headers": {
       "Cache-Control": "no-cache"
     }
   },
   "2": {
     "Method": "GET",
     "Resource": "https://piafhar-sto-01/piwebapi/streamsets/interpolated?webID=P03rCkp0judEazHPxrmYHHRQ-RgAAAUElIQVItU1RPLTAxXFRLTlQwNTIxLkdST1NTUVRZ&webID=P03rCkp0judEazHPxrmYHHRQ-xgAAAUElIQVItU1RPLTAxXFRLTlQwNTIxLkZSRUVRVFk&webID=P03rCkp0judEazHPxrmYHHRQBRkAAAUElIQVItU1RPLTAxXFRLTlQwNTIxLkxFVkVM&startTime=10/01/2016%2000:00&endTime=10/03/2016%2000:00&interval=15m",
     "Content": "{\"Name\":\"New Element\"}",
     "Headers": {
       "Cache-Control": "no-cache"
     }
   }
  };

  $.ajax({
     type: "POST",
     url: "https://piafhar-sto-01/piwebapi/batch",
     dataType: 'json',
     async: true,
     data: req,
     success: function(piData) {
      console.log(piData)
  },
     cache: true,
  error: function (xhr) {
  console.log(xhr.responseText);
  },
    beforeSend: function (xhr) {
  xhr.setRequestHeader('Authorization', 'Anonymous');
    }
  });

}





dd

Outcomes