You need to sign in to do that
Don't have an account?
http post for mulitpart form
I am trying to post the csv data through http post to end point url.
Below is my code.
string test = 'test1,test1@gmail.com'; // which will be get from DB and make as CSV string
String header = '--'+boundary+'\n'; //boundary is random string
String footer = '\n'+boundary+'--';
String bodyText = 'Content-Disposition: form-data; name="upload";'
+ '\nfilename="test.csv"'
+ '\nContent-Type: text/csv'
+ '\n' + test;
String body = header + bodyText + footer;
req.setHeader('Content-Type','multipart/form-data; boundary='+boundary);
req.setHeader('Content-Length',String.valueof(body.length()));
req.setMethod('POST');
req.setEndpoint(myendpoint);
req.setBody(body);
req.setTimeout(60000);
The problem is I couldn't able to post the data.
I make query from DB and make the data as CSV string.
Then put those CSV string in request body.
The requirement is I need to post the file.
Is it because the request can't be done successfully as I am making CSV string and put into request body?
Can anyone give me headstart?
I have been stuck on this problem quite long time now.
PS: I even tested whether my request header are right or not with posttestserver.com with REST client firefox plug in. Still can't post. Pls check out the test result. http://www.posttestserver.com/data/2013/07/01/01.18.49320686031
All Answers
Have you actually processed the same ? By doing something like
Http http = new Http();
HTTPResponse res = http.send(req);
Hi Avidev9,
Yes. I do post like you have mentioned.
The problem is I am just getting 500 [Unhanled Exceptions] from the end point that I am trying to call.
1) My Question is whether my request format is correct or not? Can you take a look?
2) As I want to post CSV data in request body, the way I append CSV as String to request body is correct or not?
3) Any alternative approach (references) for posting multipart form data in the http post request.
Thanks ahead.