Send multipart/form-data when calling API via OPENROAD

34 views
Skip to first unread message

Jan

unread,
Oct 9, 2024, 9:53:16 PM10/9/24
to OpenROAD Users Mailing List
Hi,

Good day.

I'm trying to call an API via OPENROAD client using url connection.
I was able to send a POST request when the content-type is application/json. but, how do i send a POST request when sending a multipart/form-data

here's my current code:

DECLARE
    urlc = UrlConnection;
    rstr = StringObject;
rv = INTEGER NOT NULL;
arr = array of stringobject;
str = stringobject;


ENDDECLARE
{



str.value = '{"from":"email",'+
'"subject":"sample",'+
'"text":"sample2"' +
'"to":"email"'+
'}';

arr[1].value = 'Authorization: App xxxxx';
arr[2].value = 'Content-Type: multipart/form-data; boundary=--???--';

    urlc.SetOption(option = CURLOPT_URL,
        value = 'url');
       
    urlc.SetOption(option = CURLOPT_SSL_VERIFYPEER, value = FALSE);
    urlc.SetOption(option = CURLOPT_POSTFIELDS,
        value = str.value
);

urlc.SetOption(option = CURLOPT_CUSTOMREQUEST, value = 'POST');

    urlc.SetOption(option = CURLOPT_HTTPHEADER,
      value = arr);
   
    urlc.OutputObject = rstr;
rv = urlc.Perform();
    IF urlc.Perform() = ER_OK THEN
        CurExec.Trace(string = urlc.OutputObject);
    ELSE
        CurExec.Trace(text = urlc.Errortext);
    ENDIF;
}

Can anybody help me?, I'm fairly new to using URLC on Openroad.

Thank you.

Regards,
Edmond

Adrian Williamson

unread,
Oct 10, 2024, 4:37:41 AM10/10/24
to openroa...@googlegroups.com

>I'm fairly new to using URLC on Openroad

 

I fear we all are, well apart from the author….

 

I do not have a specific answer for you here, but I am in the same boat working out how to apply OAuth2.0 security features to API calls.

 

I found that by searching out answers to my questions in curl I was able to reverse engineer the solution.

 

Also a product called Postman has been a help as well, in that I can get the curl syntax for a call after working through its GUI.

 

I think the OpenROAD manuals would benefit from telling you what the curl command line option is for all those ‘options’ to speed things up.

 

e.g. CURLOPT_SSL_VERIFYPEER is -k

 

I am still pondering the ‘info’ section to see if I can get it to give me a fully formed command line curl command post-perform (hint hint)

 

So I would disappear down the rabbit hole that starts with things like this:

 

https://stackoverflow.com/questions/19116016/what-is-the-right-way-to-post-multipart-form-data-using-curl

 

Good luck, and please share.

 

Cheers

 

Adrian

--
You received this message because you are subscribed to the Google Groups "OpenROAD Users Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openroad-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/openroad-users/08059024-acec-403b-919a-ef72c5e09b3en%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages