我不斷收到空值,而發送這兩個參數通與阿賈克斯一POST(試圖與海報以及):在REST接收空值資源
@POST
@Path("/update")
@Produces(MediaType.APPLICATION_JSON)
public void update(String Path, String Content) {
updateURI(Path,Content);
}
路徑:http://essam.ldm.io/stor...amblog/ChannelList/ch1/post2
內容:<http://essam.ldm.io/storage/essamblog/ChannelList/ch1/post2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://crosscloud/mblog/Post>. <http://essam.ldm.io/storage/essamblog/ChannelList/ch1/post2> <http://crosscloud/mblog/owner> <https://essam.ldm.io></https:>. <http://essam.ldm.io/storage/essamblog/ChannelList/ch1/post2> <http://purl.org/dc/terms/created> <2013-03-06T16:41:18+0300^^http://www.w3.org/2001/XMLSchema#dateTime>. <http://essam.ldm.io/storage/essamblog/ChannelList/ch1/post2> <http://rdfs.org/sioc/ns#content>.
很顯然,由於格式不同,我無法將它們發送爲@QueryParam
或@PathParam
。
這是irrilevant把jQuery代碼,因爲它deosnt與海報wotk沒有,但在這裏它是:
function doUpdate(path, rdf)
{
var obj1 = {"path": path, "rdf": rdf};
var sUrl = "http://localhost:8080/browsing/services/RDF/update";
$.ajax({
type: "POST",
url: sUrl,
contentType: "application/json; charset=utf-8",
data: obj1,
//dataType: "json",
async: false,
success: function (resp, status, xhr) {
$("#message").html("STATUS: " + xhr.status + " " + xhr.statusText + "\n" + resp);
$("#message").hide();
$("#login_message").html("<font color='green'><b>Record succesfully updated</b></font>d");
},
error: function(resp, status, xhr){
$("#message").html("ERROR: " + resp.status + " " + resp.statusText + "\n" + xhr);
$("#message").show();
}
});
}
什麼我做錯了嗎?
感謝,
現在試着創建一個像你所建議的XmlRootEelement,但編碼我嘗試過「var sRdf = encodeURIComponent(rdf)」,但它改變了引號中的一些標籤..等等。 – mzereba 2014-09-28 13:21:37
如果您想使用編碼,請使用base64。 http://scotch.io/quick-tips/js/how-to-encode-and-decode-strings-with-base64-in-javascript – 2014-09-28 13:31:21
編碼工作,但我得到了400錯誤的請求,並告訴我「服務器拒絕此請求是因爲請求實體的格式不是所請求方法的請求資源支持的格式。「 – mzereba 2014-09-29 08:30:51