About multipart/form-data and boundary=MIMEBoundary_* - wso2

Currently i am using WSO2 API manager 1.8.0 to secure my web service endpoints . There is a end point allow to upload file and text (multipart/form-data). Firstly, I have invoked the endpoint directly and got success. Then i create a API by using WSO2 AM and provide upload file end point for production and sandbox url. After invoked, i got exception regarding to "Body part ended prematurely. Boundary detected in header or EOF reached."
I have investigated and see that the content type is changed
This is the correct one:
Content-Type: multipart/form-data; boundary=a65f7a9e-30a7-41ce-986b-e0ba8678cd7d
--a65f7a9e-30a7-41ce-986b-e0ba8678cd7d
Content-Disposition: form-data; name="type"
Content-Type: application/x-www-form-urlencoded
MY_DA_TA
--a65f7a9e-30a7-41ce-986b-e0ba8678cd7d--
And this is the difference
Content-Type: multipart/form-data; charset=UTF-8; boundary=MIMEBoundary_f7e66aa74d83cdf3eca30fd8f62eff42fd5b2e5d627e4e78
--2819d1cd-319b-4d7b-9685-b9944b6e22e5
Content-Disposition: form-data; name="type"
Content-Type: application/x-www-form-urlencoded
MY_DA_TA
--2819d1cd-319b-4d7b-9685-b9944b6e22e5--
How can i correct that ?

Just by glance I found a similar query [1]. Could you check if that works for you.
[1] multipart form data file upload using WSO2 API manger ?

Related

AWS S3 PUT Example using REST API

The AWS S3 PUT REST API docs are lacking a clear example of the Authorization string in the Request Syntax.
Request Syntax
PUT /Key+ HTTP/1.1
Host: Bucket.s3.amazonaws.com
x-amz-acl: ACL
Cache-Control: CacheControl
Content-Disposition: ContentDisposition
Content-Encoding: ContentEncoding
Content-Language: ContentLanguage
Content-Length: ContentLength
Content-MD5: ContentMD5
Content-Type: ContentType
Expires: Expires
x-amz-grant-full-control: GrantFullControl
x-amz-grant-read: GrantRead
x-amz-grant-read-acp: GrantReadACP
x-amz-grant-write-acp: GrantWriteACP
x-amz-server-side-encryption: ServerSideEncryption
x-amz-storage-class: StorageClass
x-amz-website-redirect-location: WebsiteRedirectLocation
x-amz-server-side-encryption-customer-algorithm: SSECustomerAlgorithm
x-amz-server-side-encryption-customer-key: SSECustomerKey
x-amz-server-side-encryption-customer-key-MD5: SSECustomerKeyMD5
x-amz-server-side-encryption-aws-kms-key-id: SSEKMSKeyId
x-amz-server-side-encryption-context: SSEKMSEncryptionContext
x-amz-request-payer: RequestPayer
x-amz-tagging: Tagging
x-amz-object-lock-mode: ObjectLockMode
x-amz-object-lock-retain-until-date: ObjectLockRetainUntilDate
x-amz-object-lock-legal-hold: ObjectLockLegalHoldStatus
Body
The docs show this request example further on...
PUT /my-image.jpg HTTP/1.1
Host: myBucket.s3.<Region>.amazonaws.com
Date: Wed, 12 Oct 2009 17:50:00 GMT
Authorization: authorization string
Content-Type: text/plain
Content-Length: 11434
x-amz-meta-author: Janet
Expect: 100-continue
[11434 bytes of object data]
But again, the doc does not have an example format for Auth String. I tried AccessKeyID Secret but that didn't work. I dont' even see logical parameters in the request syntax to pass the two parts of the credential (AccessKeyID and Secret) anywhere in the examples!
Does anyone have a simple example of how to use PUT to add a .json file to S3 using the REST API? Preferrably a screenshot of PostMan setup to better explain where values go (in URL vs. as headers).
From the AWS docs here, it appears it is not possible to create a PUT request to an S3 bucket using REST API alone:
For authenticated requests, unless you are using the AWS SDKs, you have to write code to calculate signatures that provide authentication information in your requests.
This is a new concept to me. I've used token requests and sending keys in headers before when authenticating via REST API's. It sounds like a more secure method of auth.

Parse multipart/form-data json body of lambda in Java

I am trying to implement a Lambda function that receives a POST request containing data encoded as multipart/form-data. The message is received through the API Gateway using Lambda Proxy integration and the body is encoded in Base64 when it arrives to the Lambda function. After decoding it manually, I see it contains a multipart body like the following:
-----WebKitFormBoundary3EZ0C3tbP2JpAmz4
Content-Disposition: form-data; name="param1"
value1
-----WebKitFormBoundary3EZ0C3tbP2JpAmz4
Content-Disposition: form-data; name="param2"
value2
------WebKitFormBoundary3EZ0C3tbP2JpAmz4
Content-Disposition: form-data; name="myfile"; filename="ivr.png"
Content-Type: image/png
PNG
... [binary stuff]
------WebKitFormBoundary3EZ0C3tbP2JpAmz4--
What I need is to parse this message in java 8.
so that I can access the individual parts like
1. form data
2 file content
I have tried fileupload, Apache Multipart those didn't workout
Any sols will be helpful.
I ran into a similar issue with my application. I used and modified a custom form-data parser here: https://apimeister.com/2015/10/10/formdatahandler-implements-com-sun-net-httpserver-httphandler.html
I got it to parse properly however, the binary data came in malformed similar to this issue here: https://github.com/dherault/serverless-offline/issues/230
How did you get the entire AWS Lambda body to encode to base64? Can you post instructions to do so? That may fix the malformed data issue I am running into.

Soap request body using 'postman' chrome app

How would the body of a soap request look like for the 'holiday web service' (http://www.holidaywebservice.com/HolidayService_v2/HolidayService2.asmx?wsdl) using the Postman google app?
I'm trying to use the getHolidaysAvailable method. I have tried the suggested format found on the holidaywebservice.com site but it does not work. In short, can anyone successfully post to this web service using Postman and share the soap request headers and body you use. Thanks!
Method needs to be POST and use http://www.holidaywebservice.com//HolidayService_v2/HolidayService2.asmx?wsdl as the URL.
You must include the following in the Headers:
Content-Type: text/xml; charset=utf-8
You can add SOAPAction in the headers but is not necessary for this web service request to work as the request body will specify which SOAP Method to use, 'GetHolidaysAvailable'.
SOAPAction: "http://www.holidaywebservice.com/HolidayService_v2/GetHolidaysAvailable"
Finally, the Body should look like this:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.holidaywebservice.com/HolidayService_v2/">
<SOAP-ENV:Body>
<ns1:GetHolidaysAvailable>
<ns1:countryCode>UnitedStates</ns1:countryCode>
</ns1:GetHolidaysAvailable>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Your request could be something like this even:
POST /HolidayService_v2/HolidayService2.asmx/GetHolidaysAvailable HTTP/1.1
Host: www.holidaywebservice.com
Cache-Control: no-cache
Content-Type: application/x-www-form-urlencoded
countryCode=UnitedStates

Force Internet Explorer to read POST message without downloading it

I have a scenario in which a client application sends a POST request to an asp.net page to which the page responds with a json string which I need to consume on the client side.
However, Internet explorer is trying to download the *.aspx page, containing the json string.
What HTTP headers must the response contain to disable the download in Internet Explorer?
Currently, the response HTTP headers are:
Access-Control-Allow-Headers:X-File-Name,X-File-Type,X-File-Size
Access-Control-Allow-Methods:GET,POST,OPTIONS
Access-Control-Allow-Origin:*
Cache-Control:private,private, no-cache
Content-Length:1050
Content-Type:application/json; charset=utf-8
Date:Fri, 12 Jul 2013 08:24:24 GMT
Pragma:no-cache
Server:Microsoft-IIS/7.5
Set-Cookie:ASP.NET_SessionId=qjudp3nct3czltyvc4yxpiri; path=/; HttpOnly
X-AspNet-Version:4.0.30319
X-Powered-By:ASP.NET
It depends on how you are consuming that web service.
If you are consuming it from inside a web page using jQuery, it shouldn't be a problem, Internet Explorer won't force download the file.
If you access the file directly after the POST (redirect to the URL that serves the JSON) and you want to display the JSON as plain text, you must set the Content-Type to text/plain; charset=utf-8

Able to GET authenticate but not POST authenticate

I am trying to connect to a REST API, using C#.
I was able to successfully do some GET request but POST kept giving me 401 Authentication error.
I have gone ahead and downloaded fiddler and this is what my requests look like:
GET (Works)
Request Headers
GET https: //hello.myurl.com/api HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Accept: application/xml
Authorization: Basic ***************************************************************************************************
Host: hello.myurl.com
-
POST (Doesn't work)
Request Headers
POST https: //hello.myurl.com/api HTTP/1.1
Content-Type: application/x-www-form-urlencoded
Accept: application/xml
Authorization: Basic ***************************************************************************************************
Host: hello.myurl.com
Content-Length: 12
Request Body
status=hello
(* same in both using
String authinfo = "username:password";
Convert.ToBase64String(Encoding.ASCII.GetBytes(authInfo));
Any ideas why?
I'd consult the API documentation for that particular URL. GET requests are simply requesting a readonly version of data, a POST request is implying that you are making a change to a certain URL, so it's possible that the API allows GET requests without authentication, but requires authentication on the POST request.
In your case I'd hazard a guess that your authentication is not correct, but it's just being ignored on the GET request as it doesnt need authentication.