cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X

Send Primary Content via POST HTTP request

VanVelZ
7-Bedrock

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

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
HelesicPetr
22-Sapphire I
(To:VanVelZ)

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

View solution in original post

4 REPLIES 4
HelesicPetr
22-Sapphire I
(To:VanVelZ)

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

Thank you very much. For clarity, how would I surface the primary content from a WTObject?

HelesicPetr
22-Sapphire I
(To:VanVelZ)

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

@HelesicPetr for the win!

Top Tags