PHP から json を POST したい REST URL (DropWizard を使用して Java でコーディング) があります。しかし、私は415 Unsupported MediaType
エラーが発生しています。多くのフォーラムを調べましたが、エラーの原因がわかりません。両端の私のコードは次のとおりです。
サーバ
@POST
@Path("/update-table")
@Timed
public TableUpdateResponse updateTable(TestClass testObj) {
LOG.info("inside updateTable function");
//other code ...
}
クライアント
<?php
$url = "localhost:8084/update-table"
$ch = curl_init($url);
$jsonString = array("testString" => "Hello World!");
$json = json_encode($jsonString);
$headers = array();
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
echo $response;
?>
テストクラス
public class TestClass {
private String testString;
public TestClass(String testString) {
super();
this.testString = testString;
}
public TestClass() {
super();
}
public String getTestString() {
return testString;
}
public void setTestString(String testString) {
this.testString = testString;
}
}
リクエストが REST に到達していません (LOG 行が出力されません)。ここで何が欠けていますか?