簡體   English   中英

WebClient C#不支持URI格式

[英]URI formats are not supported in webclient c#

如您所見,我致電我的服務:

  public ReceptionView ReceptionViewByReceptionId(string receptionId)
    {
        ClientRequest.Headers["Content-type"] = "application/json";
        ClientRequest.Encoding = System.Text.Encoding.UTF8;
        string result = ClientRequest.DownloadString("http://localhost:1111" + " /ReceptionService.svc/ReceptionViewByReceptionId/" + receptionId);

        var javascriptserializer = new JavaScriptSerializer();
        return javascriptserializer.Deserialize<ReceptionView>(result);
    }

但是我在DownloadString收到此錯誤:

{"URI formats are not supported."} 

我的服務正常,當我通過瀏覽器調用我的服務時,如下所示:

http://localhost:1111/ReceptionService.svc/ReceptionViewByReceptionId/1

我得到了預期的結果。但是在我的應用程序中,我無法

我的服務界面

 [WebGet( UriTemplate = "/ReceptionViewByReceptionId/{receptionId}", RequestFormat = WebMessageFormat.Json,
    ResponseFormat = WebMessageFormat.Json)]

    ReceptionView ReceptionViewByReceptionId(string receptionId);

值得注意的是,我的函數之前沒有任何錯誤,但是今天突然返回了此錯誤。

我的提琴手在瀏覽器中得到結果: 在此處輸入圖片說明

問題是這里的空格" /Reception ,您可以在url中看到

string result = ClientRequest.DownloadString("http://localhost:1111" + " /ReceptionService.svc/ReceptionViewByReceptionId/" + receptionId);

我刪除了所有內容,一切正常。

暫無
暫無

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

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