我有一個REST URL(使用DropWizard編碼),我想從PHP POST JSON。但是我得到415 Unsupported MediaType
錯誤。我查了很多論壇,我無法弄清楚錯誤可能是什麼。我在兩端代碼如下:POST JSON到REST從PHP
服務器
@POST
@Path("/update-table")
@Timed
public TableUpdateResponse updateTable(TestClass testObj) {
LOG.info("inside updateTable function");
//other code ...
}
CLIENT
<?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;
?>
的TestClass
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行不打印)。我在這裏錯過了什麼?
我想問題是與PHP代碼,因爲,我嘗試從終端curl命令,它的工作原理。 – Neo