I'm not sure what exactly I can do to see what my issue is with my POST request. I had made a quick prototype in PHP using the CURL libraries to construct my request. When I try to do the same function in a JSP page I am getting a HTTP error 415. I'm unsure how to fix it. I have gotten the correct in both the PHP page and on a web debugger (fiddler) without error. I was also able to do a successful get request on this JSP page with another part of the REST api I'm using. What can I do to find the issue?
Here is the JSP code
String xmlRequest = "<viewParameters><vslText>[field1] = '01510486'</vslText></viewParameters>";
try
{
URL url = new URL("*****");
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
//Connection Properties
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setFollowRedirects(true);
//Header Parameters
conn.addRequestProperty("X-IntegrationServer-Username", "******");
conn.addRequestProperty("X-IntegrationServer-Password", "*******");
conn.setRequestProperty("ContentType", "application/xml");
conn.setRequestProperty("Host", "*********");
conn.setRequestProperty("Content", "viewParameters");
conn.setRequestProperty("Accept", "application/xml");
//Post Parameter
OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream());
writer.write(xmlRequest);
conn.connect();
//CHECK HTML RESPONSE
out.print("<br>Response code = " + conn.getResponseCode());
out.print("<br>Response message = " + conn.getResponseMessage() + "<br><br>");
//Output Here
InputStream input = conn.getInputStream();
//Takes XML and puts it into one string variable
BufferedReader inputReader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuilder sb = new StringBuilder();
String inline = "";
while ((inline = inputReader.readLine()) != null) {
sb.append(inline);
}
inputReader.close();
out.print(sb.toString());
} catch (Exception e) {
e.printStackTrace();
}
Here is the working PHP code
<?php
$curl = curl_init();
//xml to send to server
$xmlRequest = "<viewParameters><vslText>[field1] = '********'</vslText></viewParameters>";
//took out 'Content-Length: ' . strlen($xmlRequest)
$requestParam = array('X-IntegrationServer-Username: ********', 'X-IntegrationServer-Password: ************', 'Host: *************', 'Content-Type: application/xml', 'Content: viewParameters');
curl_setopt($curl, CURLOPT_HTTPHEADER, $requestParam);
curl_setopt($curl , CURLOPT_URL, '***************');
//stops SSL errors but also turns off security for it check this link http://stackoverflow.com/questions/21187946/60-ssl-certificate-self-signed-certificate-in-certificate-chainbool
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $xmlRequest);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($curl);
//if no response comes through tries to give error message
if(!$response){
die('Error: "' . curl_error($curl) . '" - Code: ' . curl_errno($curl));
}
curl_close($curl);
$xml = simplexml_load_string($response);