小编Adi*_*dil的帖子

Glassfish与Tomcat的RESTful服务

我有一个.net开发背景,但对Java世界来说相对较新.我们已经开始使用JAX-RS开发RESTful服务(公共Web API),主要由移动平台(Android,iPhone,Windows Phone等)使用.

  1. 我们需要一些关于选择适当服务器的指导,如Tomcat或Glassfish等?请分享理由.
  2. 另请指导我们对JAX-RS的决定是否适合构建RESTful服务.

rest tomcat glassfish

16
推荐指数
1
解决办法
1万
查看次数

为什么整个HttpResponseMessage序列化?

为什么要使用这个Web API

[HttpGet("hello")]
public HttpResponseMessage Hello()
{
    var res = new HttpResponseMessage(HttpStatusCode.OK);
    res.Content = new StringContent("hello", Encoding.UTF8, "text/plain");
    return res;
}
Run Code Online (Sandbox Code Playgroud)

返回

{
  "Version":{
    "Major":1,
    "Minor":1,
    "Build":-1,
    "Revision":-1,
    "MajorRevision":-1,
    "MinorRevision":-1
  },
  "Content":{
    "Headers":[{
      "Key":"Content-Type",
      "Value":["text/plain; charset=utf-8"]
    }]
  },
  "StatusCode":200,
  "ReasonPhrase":"OK",
  "Headers":[],
  "RequestMessage":null,
  "IsSuccessStatusCode":true
}
Run Code Online (Sandbox Code Playgroud)

代替

hello
Run Code Online (Sandbox Code Playgroud)

如何让Web API返回如下所示的HTTP响应?

200 OK
Content-Type: text/plain

hello
Run Code Online (Sandbox Code Playgroud)

我最终想要做的是返回JSON和其他具有各种状态代码的格式,因此以下代码不能帮助我作为答案.

[HttpGet("hello")]
public string Hello()
{
    return "hello";
}
Run Code Online (Sandbox Code Playgroud)

(我是ASP.NET和其他Microsoft技术的新手.)

c# asp.net asp.net-web-api

5
推荐指数
1
解决办法
1409
查看次数

这个 TextReader 有什么问题吗?

我正在使用这段代码从文件中读取,但出现错误“无法创建抽象类或接口“System.IO.TextReader”的实例”

using (FileStream fileStream = File.Open(fileName, FileMode.Open, FileAccess.Read))
       using(TextReader reader = new TextReader(fileStream))//error
       {
           ...       
       }
Run Code Online (Sandbox Code Playgroud)

c# io filestream

1
推荐指数
1
解决办法
1951
查看次数

标签 统计

c# ×2

asp.net ×1

asp.net-web-api ×1

filestream ×1

glassfish ×1

io ×1

rest ×1

tomcat ×1