Send Primary Content via POST HTTP request
Aug 28, 2023
03:46 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Aug 28, 2023
03:46 PM
Send Primary Content via POST HTTP request
When certain documents update, I need to send the primary content via an HTTP POST request. I am having trouble finding any supporting documentation and was wondering if it was possible. If so, how.
Thank you in advance
Solved! Go to Solution.
Labels:
ACCEPTED SOLUTION
Accepted Solutions
Aug 29, 2023
03:56 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Aug 29, 2023
03:56 AM
Hi @VanVelZ
It is simple. Just write primary content to http as a outputstream.
example uses a xml file
URL urlObj = new URL("http://adressToApplication");
HttpURLConnection con = (HttpURLConnection) urlObj.openConnection();
con.setSSLSocketFactory(sslsocketfactory);// it is up to you what security you use
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "text/xml; charset=UTF-8");
con.setRequestProperty("Accept", "text/xml");
con.setRequestProperty("Content-Length", String.valueOf(xmlContent.length()));
con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.write(xmlContent.getBytes(StandardCharsets.UTF_8));
wr.flush();
wr.close();
PetrH
4 REPLIES 4
Aug 29, 2023
03:56 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Aug 29, 2023
03:56 AM
Hi @VanVelZ
It is simple. Just write primary content to http as a outputstream.
example uses a xml file
URL urlObj = new URL("http://adressToApplication");
HttpURLConnection con = (HttpURLConnection) urlObj.openConnection();
con.setSSLSocketFactory(sslsocketfactory);// it is up to you what security you use
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "text/xml; charset=UTF-8");
con.setRequestProperty("Accept", "text/xml");
con.setRequestProperty("Content-Length", String.valueOf(xmlContent.length()));
con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.write(xmlContent.getBytes(StandardCharsets.UTF_8));
wr.flush();
wr.close();
PetrH
Aug 29, 2023
09:49 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Aug 29, 2023
09:49 AM
Thank you very much. For clarity, how would I surface the primary content from a WTObject?
Aug 29, 2023
10:10 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Aug 29, 2023
10:10 AM
Hi @VanVelZ
ContentHelper can help you 😄
WTDocument document = Util.GetDocument("ABCD"); // my own function to get WTDocument - you can use what object you need
ApplicationData syAppData = (ApplicationData) ContentHelper.service.getPrimaryContent(ObjectReference.newObjectReference(document));
InputStream is = ContentServerHelper.service.findContentStream(syAppData ); // InputStream needs to be converted to OutputStream for HTTP OutputStream.
PetrH
Aug 29, 2023
11:29 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
