Response type "pass through" works as expected, but when I changed it to "XML" only GET requests works - ibm-datapower

I have a MPG that, until now, the request and response were defined as "pass through", but now I want to ensure that the request is XML.
I defined the Request Type as "XML", and now only GET requests make it through to the server.
In the probe I see, what seems to me, a perfectly valid XML, but after the implied filter it drops it with error 'rejected'.
I'm sending the XML, to test, via curl as such curl -X POST -d '<note>value</note>' -H 'Content-Type: application/xml' http://1.2.3.4:5678

Related

How to set the Content-Type differently for each key value when requesting POST with multipart/form-data in Golang

When requesting POST with multipart/form-data using Golang, is there a way to send the request by setting the content-type differently for each key? For example, one key will send a file, and one key will send data in json format in application/json type. It was possible with postman, but I couldn't find a way to do it with Golang. If you know, please share it with me. Thank you. :)
Below is the cURL of the successful request value in postman.
curl --location --request POST '{API_URL}' \
--header 'Cookie: JSESSIONID={}' \
--form 'images=#"{dsfsdfs.png}"' \
--form 'request="{ \"id\": \"yoon\", \"memberName\": \"yoon\"}";type=application/json'
And when I tried several times in Golang, I got an error requesting the content type 'application/octet-stream'.

Why does the postman post request not send body variables?

I am attempting to send a plain POST request via Postman. I did the same via Curl and my server sees it just fine. Here is the settings for the Body:
And here is the request in the console:
My express server is not seeing the body variables. With curl like this it does:
curl -X POST https://xxx.appspot.com -d "volume=123&content=foobar"
What do I need to change for this to work?
The two examples are not equivalent, because with Postman you have Content-Type: text/plain header set, but sending data via curl -d option, sets Content-Type: application/x-www-form-urlencoded. From curl manual page:
-d, --data <data>
(HTTP MQTT) Sends the specified data in a POST request to the
HTTP server, in the same way that a browser does when a user has
filled in an HTML form and presses the submit button. This will
cause curl to pass the data to the server using the content-type
application/x-www-form-urlencoded.
I don't have any experience with Postman, but my guess would be you need to select x-www-form-urlencoded button instead of current raw button.

Request parameters are not passed to the backend service

I configured a REST webservice (a Spring Boot webapplication) on WSO2 AM and used the default /* mapping for resources. My webservice takes an assignee (text) and file parameters.
When I perform the calls, I've noticed that request parameters are not forwarded (HTTP Headers are) to the backed services. For example:
curl -i -X POST -H "Content-Type: multipart/form-data" -H "X-PD20-BillingSubscriptionId: e87d4400-b05f-4f40-9c39-06ae4d28cf4d" -H "Authorization: Bearer rrxRV5F6jdkSBcEPXv7I1yFl2x8a" -F "documentFile=#src/test/resources/sample-files/test-fea-1firma.pdf" -F "assignee=bla.bla#gmail.com" http://api.linksmt.it:8280/fea/1.0.0/signRequest
As you can see, It's a form that posts 2 fields, one of them being a file and another a simple text field.
The call is succesfully forwarded to the backed service but without the actual fields values (the headers instead are correctly passed, though their keys are lower-cased, that is "X-PD20-BillingSubscriptionId" is passed as "x-pd20-billingsubscriptionid").
Any hint on why is this happening?
Thanks
Ok, the problem was the same as described in multipart form data file upload using WSO2 API manger ? and I had to uncomment the declarations for
within the $WSO2_AM/repository/conf/axis2/axis2.xml file (and restart the server).

How do I find the correct url to send curl POST request to?

I am trying to use curl to send a POST request with json.
I use Live HTTP Headers and get the url to send the request to. However it comes back "request denied. you do not have permission to access this page?"
How do I find the correct url?
from Live Http headers, i can see the json data {"var1":"val1","var2":"val2",...}
so i use the following curl command:
curl -H "Accept: application/json" -H "Content-type: application/json" -o output.html -L "http://domain.com/theurl" -d '{"var1":"val1","var2":"val2",...}'
There may be other parts of the request you observed using Live HTTP Headers that allowed your browser to access that URL, such as a cookie value that indicated your session information or user credentials. If Live HTTP Headers has the ability to view those headers and/or cookies, you could grab them and include them in your curl request using additional -H 'Header: value' arguments.
HTTP Authentication may also be used, in which case you should pass your username and password to curl with --user name:password.

How to test multipart/form-data POST request

I am trying to find a tool that will allow me to test a multipart/form-data POST request and tweak the request. Specifically, I want to test the absence/presence of the semi-colon in the content-type header:
multipart/form-data; boundary=140f0f40c9f411e19b230800200c9a66
We have a client that doesn't send a semi-colon and our new servlet (using Apache Commons FileUpload) can't parse the uploaded file. The old version of our servlet uses a different library method for accepting/parsing the request and it can parse the file. Until I can prove that the request will be successful by including the semi-colon, the owners of the client app don't want to make any changes to it.
I have been using cURL to run my tests against the servlet, but I can't tweak the request it generates to exclude the semi-colon. I have tried the Poster addon for Firefox and Fiddler to generate a test POST request, but they result in this error:
org.apache.commons.fileupload.FileUploadException: Stream ended unexpectedly
Has anybody found a way to successfully test a multipart/form-data POST request with an uploaded file?
You can use curl for testing these libraries, here's an example using a multipart/form-data POST: https://stackoverflow.com/a/10765244/72176
One thing I like about a command-line tool like curl is it's easy to repeat (in bash, up & enter), and you can save the test for later.
Edit: It is definitely possible to send the custom header that you want to test. The key is to use curl's raw commands over the convenience methods which format the request for you. Use -H to pass in the raw header, and use --data-binary to pass in the body from a file without changing the line endings (very important for multipart/form-data which must have CRLF line endings). Here's an example:
curl -X POST -H "Content-Type: multipart/form-data; boundary=----------------------------4ebf00fbcf09" --data-binary #test.txt http://localhost:3000/test
of if it's more convenient not to use the intermediary file, you can write it one line like so:
curl -X POST -H "Content-Type: multipart/form-data; boundary=----------------------------4ebf00fbcf09" -d $'------------------------------4ebf00fbcf09\r\nContent-Disposition: form-data; name="example"\r\n\r\ntest\r\n------------------------------4ebf00fbcf09--\r\n' http://localhost:3000/test
These 2 examples include the semicolon, but you can remove it as needed.

Resources