2016-11-21 225 views
-3

我有一個web api控制器,我需要在Java客戶端中使用它,但是證書存在問題,所以我需要使用HTTP而不是HTTPS。在WEB API中強制通過HTTPS實現HTTP DotNet

public static class WebApiConfig 
{ 

    public static void Register(HttpConfiguration config) 
    { 
     config.MapHttpAttributeRoutes(); 

     config.Routes.MapHttpRoute(
      name: "DefaultApi", 
      routeTemplate: "api/{controller}/{id}", 
      constraints : null, 
      defaults: new { id = RouteParameter.Optional } 
     ); 
     config.Formatters.Remove(config.Formatters.XmlFormatter); 
     config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new System.Net.Http.Headers.MediaTypeHeaderValue("application/json")); 
    } 
} 


public class CommentAPIController : ApiController 
{ 
    IItemService ise = new ItemService(); 
    ICategoryService ice = new CategoryService(); 
    // GET: api/CommentAPI 
    [HttpGet] 
    public IEnumerable<Category> Get() 
    { 
     List<Category> list = new List<Category>(); 
     foreach (Category item in ice.getAllCategory()) 
     { 

      list.Add(item); 



     } 
     return list; 
    } 

感謝您的幫助

+0

當您在不使用'https'的情況下調用網址時是否出現錯誤? –

+0

沒有頁面只是繼續加載 –

+0

你如何主持這個應用程序?你是從Visual Studio運行它,還是已經在IIS上發佈? –

回答

0

請編輯Web API項目的屬性(右鍵單擊該項目,然後屬性,或展開項目的內容和屬性組雙擊)。

然後導航到Web屏幕,看看您的任何網址是否指向https

如果是,請將其更改爲http://並重新啓動。通常你必須使用[RequireHttps]屬性強制https,所以你的問題似乎相反。

根據我們在評論中的討論。最後,您已經提供了錯誤的HTTPS服務端口,該端口與我指出的完全相同。

讓我們繼續爲其他人。