簡體   English   中英

請求方法“ DELETE”未在Web服務中調用方法

[英]Request Method “DELETE” not calling a method in web service

我需要調用方法cancel,但是系統不會調用該方法,並且不會顯示任何錯誤。

url = new URL("http://localhost/api/Service.svc/Method/cancel");
con = (HttpURLConnection) url.openConnection();
con.setRequestProperty("Content-Type", "application/json");
con.setRequestProperty("Accept", "application/json");
con.setRequestProperty("Authorization", "Basic " + Base64.encodeToString("user:password".getBytes(), Base64.NO_WRAP ));
con.setRequestMethod("DELETE");
con.connect();

在我的服務器C#中:

[OperationContract]
[WebInvoke(Method = "DELETE", BodyStyle = WebMessageBodyStyle.Bare, 
RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, 
UriTemplate = "/cancel")]
void Cancel();

什么東西少了?

更新:我插入代碼con.getResponseCode()並返回值401。這是什么?

我正在解決這個問題。 插入代碼con.getResponseCode() ,系統返回410(未授權)。 為此,找到了真正的原因:Web服務WCF結構不支持動詞“ Delete”。

我將“刪除”更改為“開機自檢”,應用程序正常運行。

謝謝!!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM