単純なXMLレスポンスを返すローカルReSTサービスへのPOSTコールを作成しようとしています。ReST:POST:java.io.IOException:サポートされていないメディアタイプ
私は戻って、このエラーを取得しています:
java.io.IOException: Unsupported Media Type
at com.eric.RawTestPOST.httpPost(RawTestPOST.java:42)
at com.eric.RawTestPOST.main(RawTestPOST.java:66)
私はこの例を次のようだ:ここではLink
は私のコードです:
public class RawTestPOST {
public static String httpPost(String urlStr, String method,
String parameter, String parameterValue) throws Exception {
URL url = new URL(urlStr);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setUseCaches(false);
conn.setAllowUserInteraction(false);
conn.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");
// Create the form content
OutputStream out = conn.getOutputStream();
Writer writer = new OutputStreamWriter(out, "UTF-8");
/* for (int i = 0; i < string.length; i++) { */
writer.write(method);
writer.write("?");
writer.write(parameter);
writer.write("=");
writer.write(URLEncoder.encode(parameterValue, "UTF-8"));
writer.write("&");
/* } */
writer.close();
out.close();
if (conn.getResponseCode() != 200) {
throw new IOException(conn.getResponseMessage());
}
// Buffer the result into a string
BufferedReader rd = new BufferedReader(new InputStreamReader(conn
.getInputStream()));
StringBuilder sb = new StringBuilder();
String line;
while ((line = rd.readLine()) != null) {
sb.append(line);
}
rd.close();
conn.disconnect();
return sb.toString();
}
public static void main(String[] args) {
String url = "http://localhost:9082/ServicesWSRest/";
String method = "getResponse";
String parameter = "empID";
String parameterValue = "954";
try {
System.out.println(RawTestPOST.httpPost(url, method, parameter,
parameterValue));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
パラメータがimprtantではありません。 XMLレスポンスは、送信されたパラメータを返すだけです。
私はGETリクエストで動作させることができます。
これ以上情報が必要な場合は教えてください。 E
これは、接続しているサーバーに固有のものである可能性があります。これは、Javaネットワーキングコードではなく、サーバーから返された回答であるためです。例えば、サーバーは、要求している特定のリソースに対するPOST要求をサポートしていないことを指定することができます。接続しているサーバーに関する詳細情報を提供できますか? – Seramme