0

I have the below code and the POST params are always gibberish even though I know my entry id is valid Getting the following message - Missing parameter &quot;entryId&quot;<

Seems like the entryid is &quot

Anyone know what I am doing wrong?

 // Open a connection to the URL HttpURLConnection connection = (HttpURLConnection) url.openConnection(); // Set the request method to POST connection.setRequestMethod("POST"); // Set the request headers connection.setRequestProperty("Content-Type", "application/json"); // Enable input and output streams connection.setDoOutput(true); // Construct the POST data using parameters from the SNS message String postData = "ks=" + ks + "&entryId=" + entry + "&baseEntry[tags]=" + cleanTag + "&baseEntry[objectType]=KalturaBaseEntry"; // Write the POST data to the connection try (OutputStream os = connection.getOutputStream()) { byte[] postDataBytes = postData.getBytes(StandardCharsets.UTF_8); System.out.println("postDataBytes : "+postDataBytes ); os.write(postDataBytes); } // Get the HTTP response int responseCode = connection.getResponseCode(); System.out.println("HTTP Response Code: " + responseCode); // Read the response content try (BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()))) { String inputLine; StringBuilder response = new StringBuilder(); while ((inputLine = in.readLine()) != null) { response.append(inputLine); } System.out.println("HTTP Response Content: " + response.toString()); } // Close the connection connection.disconnect(); return true; } catch (Exception e) { e.printStackTrace(); return false; }``` Output ```2023-10-31T16:46:24.935-04:00 entry : 1_06n6re6z Link 2023-10-31T16:46:24.935-04:00 tag : Happy, Sad, Smile Link 2023-10-31T16:46:24.935-04:00 ks : djJ8NTU5OTLink 2023-10-31T16:46:25.875-04:00 postDataBytes : [B@312ab28e Link 2023-10-31T16:46:25.915-04:00 HTTP Response Code: 200 
3
  • 1
    You set Content-Type=application/json. Is the post data supposed to be JSON? You seem to be sending something that looks like URL query parameters instead. Commented Oct 31, 2023 at 20:55
  • @jarmod I changed to "application/x-www-form-urlencoded" and still same result Commented Oct 31, 2023 at 21:57
  • 1
    What is the server that you're posting to actually expecting? The equivalent of an HTML form? A JSON string? Commented Oct 31, 2023 at 22:29

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.