Skip to main content
Solved

Data Download service redirects HTTP POST requests to HTTP GET


ngoorman
Contributor
Forum|alt.badge.img+3

Hi all,

I am trying to run a workspace on FME Server (2019) through the Data Download service. This generally works fine in terms of authorization etc. I can successfully pass parameters (and directives) to it as a query string. However, one of the parameters is geometry, currently encoded as OGC Well-Known Text. The input for this parameter can become quite large, as the geometry will be passed to FME Server from a web map. When this happens, the URL exceeds tens of thousands of characters and this seems to break the request.

Because of this, I am trying to pass the request as POST, keeping all parameters in the body and thus the URL nice and short. However I can't get this to work - the parameters in the body are ignored and the workspace is run with the default parameters every time.

The FME Server Data Download logfile has this line every time:

POST request received. Redirecting to GET method.

 

Is it possible at all to use POST to start the Data Download service? If so, how do I pass parameters this way? If not, what is the suggested method to pass geometry to FME Server in such a way that I don't run into the size restriction?

I am passing a header as well, containing the token in Authorization, and 'application/json' in Accept and in Content-Type.

Best answer by richardatsafe

Hi @ngoorman,

If you x-www-form-urlencoded and send your parameter and parameter value in the body you can send tens of thousands of characters. I tested 40,000 characters of WKT in a parameter with the datadownload service using Postman, and it worked as expected. If you want to let us know what kind of issues you have having here or through a case we can help debug.

Thanks,

Richard

 

 

 

View original
Did this help you find an answer to your question?

8 replies

Hi @ngoorman! One of our colleagues suggested it should be possible to use POST with ContentType x-www-form-urlencoded. Have you tried if that works for you?


ngoorman
Contributor
Forum|alt.badge.img+3
  • Author
  • Contributor
  • March 13, 2020
alyssaatsafe wrote:

Hi @ngoorman! One of our colleagues suggested it should be possible to use POST with ContentType x-www-form-urlencoded. Have you tried if that works for you?

Hi @alyssaatsafe - I've just tried again and it does not make a difference. I constructed the headers as follows (it's a Python script):

'Content-Type' :'application/x-www-form-urlencoded',

'Accept' : 'application/x-www-form-urlencoded',

'Authorization' : 'fmetoken token={0}'.format(_fme_token)


ngoorman
Contributor
Forum|alt.badge.img+3
  • Author
  • Contributor
  • March 13, 2020
ngoorman wrote:

Hi @alyssaatsafe - I've just tried again and it does not make a difference. I constructed the headers as follows (it's a Python script):

'Content-Type' :'application/x-www-form-urlencoded',

'Accept' : 'application/x-www-form-urlencoded',

'Authorization' : 'fmetoken token={0}'.format(_fme_token)

Oh and the CORS settings allow POST, and allow these three headers (they are the default settings). I've tried setting 'Supports Credentials' to True, but this did not make any difference either.


richardatsafe
Safer
Forum|alt.badge.img+10
  • Safer
  • Best Answer
  • March 13, 2020

Hi @ngoorman,

If you x-www-form-urlencoded and send your parameter and parameter value in the body you can send tens of thousands of characters. I tested 40,000 characters of WKT in a parameter with the datadownload service using Postman, and it worked as expected. If you want to let us know what kind of issues you have having here or through a case we can help debug.

Thanks,

Richard

 

 

 


ngoorman
Contributor
Forum|alt.badge.img+3
  • Author
  • Contributor
  • March 17, 2020
richardatsafe wrote:

Hi @ngoorman,

If you x-www-form-urlencoded and send your parameter and parameter value in the body you can send tens of thousands of characters. I tested 40,000 characters of WKT in a parameter with the datadownload service using Postman, and it worked as expected. If you want to let us know what kind of issues you have having here or through a case we can help debug.

Thanks,

Richard

 

 

 

Hi @richardatsafe,

Very useful, thank you. I've installed Postman and recreated the request there (URL, body and headers). When I send it, FME Server works perfectly and accepts the parameters in the body.

When I then copy the code that Postman has generated for Python 3, and save that to a .py file and run it with Python 3, it does not work - I get the same behaviour as before where the body is ignored. The same happens when I tweak the code to work in Python 2.7 and run that way.

I have no idea what's going on though I'm happy to have confirmed that FME Server accepts the right request without issue. Python seems to do something to it that FME Server doesn't like - but even when I cut down the payload to just 'opt_responseformat=json' it doesn't work (getting HTML response instead).


ngoorman
Contributor
Forum|alt.badge.img+3
  • Author
  • Contributor
  • March 17, 2020
ngoorman wrote:

Hi @richardatsafe,

Very useful, thank you. I've installed Postman and recreated the request there (URL, body and headers). When I send it, FME Server works perfectly and accepts the parameters in the body. 

When I then copy the code that Postman has generated for Python 3, and save that to a .py file and run it with Python 3, it does not work - I get the same behaviour as before where the body is ignored. The same happens when I tweak the code to work in Python 2.7 and run that way. 

I have no idea what's going on though I'm happy to have confirmed that FME Server accepts the right request without issue. Python seems to do something to it that FME Server doesn't like - but even when I cut down the payload to just 'opt_responseformat=json' it doesn't work (getting HTML response instead).

I've now put the most basic request into Postman, against an FME sample server. Same behaviour: works fine in Postman, stops working in Python with the exported code:

 


import requests

 

url = "https://demos-safe-software.fmecloud.com/fmedatadownload/Samples/austinDownload.fmw"

 

payload = 'opt_responseformat=json'

headers = {

  'Content-Type': 'x-www-form-urlencoded',

  'Authorization': 'fmetoken token=568c604bc1f235bbe137c514e7c61a8436043070',

  'Accept': 'application/json'

}

 

response = requests.request("POST", url, headers=headers, data = payload)

 

print(response.text.encode('utf8'))


richardatsafe
Safer
Forum|alt.badge.img+10
ngoorman wrote:

I've now put the most basic request into Postman, against an FME sample server. Same behaviour: works fine in Postman, stops working in Python with the exported code:

 


import requests

 

url = "https://demos-safe-software.fmecloud.com/fmedatadownload/Samples/austinDownload.fmw"

 

payload = 'opt_responseformat=json'

headers = {

  'Content-Type': 'x-www-form-urlencoded',

  'Authorization': 'fmetoken token=568c604bc1f235bbe137c514e7c61a8436043070',

  'Accept': 'application/json'

}

 

response = requests.request("POST", url, headers=headers, data = payload)

 

print(response.text.encode('utf8'))

Hi @ngoorman,

 

I had success with my python but similar to postman I had to turn off the verify ssl certificate.  (verify=False)

 

import requests

 

url = "https://MyFMEServer/fmedatadownload/repository/WKT2.fmw"

 

payload = 'WKT=POINT%20%28-123.09875267568009%2049.25721245106853%29%20

 

headers = {

  'Authorization': 'Basic YWStbW46YWRtaW4=',

  'Content-Type': 'application/x-www-form-urlencoded'

}

 

response = requests.request("POST", url, verify=False, headers=headers, data = payload)

 

print(response.text.encode('utf8'))

 


ngoorman
Contributor
Forum|alt.badge.img+3
  • Author
  • Contributor
  • March 18, 2020
richardatsafe wrote:

Hi @ngoorman,

 

I had success with my python but similar to postman I had to turn off the verify ssl certificate.  (verify=False)

 

import requests

 

url = "https://MyFMEServer/fmedatadownload/repository/WKT2.fmw"

 

payload = 'WKT=POINT%20%28-123.09875267568009%2049.25721245106853%29%20

 

headers = {

  'Authorization': 'Basic YWStbW46YWRtaW4=',

  'Content-Type': 'application/x-www-form-urlencoded'

}

 

response = requests.request("POST", url, verify=False, headers=headers, data = payload)

 

print(response.text.encode('utf8'))

 

Hi @richardatsafe,

I've got it working now - thank you for your help. What did it was using 

'Content-Type''application/x-www-form-urlencoded' 

rather than

'Content-Type''x-www-form-urlencoded' 

The latter works in Postman but not in Python. Changing that one thing solved it - thanks again.


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings