Search code examples
c#linuxmononancy

Nancy selfhosting error on ubuntu with Mono


I am using Nancyfx as my restful api server. On windows I use Nancyfx in ASP.NET HOSTING MODE, all works fine on my App. But when I try to use a linux server, the app crushes as I use this code below

HttpClient client = new HttpClient();
HttpResponseMessage response = await client.GetAsync("http://ipaddress:1234/api/info");
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();

the exception here as below

An exception of type 'System.Net.Http.HttpRequestException' occurred in System.Net.Http.dll but was not handled in user code

Additional information: 500 (Internal Server Error)

but when I use chrome to recieve the content, seems to work fine.

HEADERS Content-Type: application/json; charset=utf-8 Date: 2016 Jun 10 17:35:31+51s Keep-Alive: timeout=15,max=100 Link: ; rel="application/xml" Server: Mono-HTTPAPI/1.0 Transfer-Encoding: chunked Vary: Accept

Is there something wrong with my code or Nancyfx selfhosting mode?

Thanks!


Solution

  • Ok, I know what's going on here. It is because the UWP app in Windows10 can not connect to local IP address like 127.0.0.1! All is fine now.