标签: httpresponsemessage

Jersey 响应的原因短语在 tomcat 7 和 8.5 中不一致

我在一台服务器上使用 Tomcat 8.5,在另一台服务器上使用 Tomcat 7,我有以下球衣资源:

@Path("main")
public class MyResource {


@POST
@Path("path")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public PojoResponse sendMailTemplate(PojoRequest paramsMap) throws Exception {
    return service.execute(paramsMap);
}
Run Code Online (Sandbox Code Playgroud)

这是注册到MyApplication( extends ResourceConfig) 与@ApplicationPath("root")

使用 JMeter/Postman(到 /root/main/path)提交请求时,我得到了不一致的 HTTP原因短语

客户端不需要检查或显示原因短语。

这对协议不是强制性的

这里列出的原因短语只是建议——它们可以被本地等效替换而不影响协议。

我从 Tomcat 7 服务器看到 200 OK 的“有效”响应:

HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: application/json
Content-Length: 32
Run Code Online (Sandbox Code Playgroud)

以及来自 Tomcat 7 服务器的 200 200 的“无效”响应(相同的请求):

HTTP/1.1 200 200
Server: Apache
Content-Type: application/json
Content-Length: 32
X-Content-Type-Options: nosniff
X-XSS-Protection: 1
Connection: close
Strict-Transport-Security: max-age=31536000; …
Run Code Online (Sandbox Code Playgroud)

java tomcat jersey httpresponsemessage tomcat8.5

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

GetAsync:不返回HttpResponseMessage

应用程序应该从LoginUser()接收httpresponsemessage但它没有响应.

    private void button1_Click(object sender, EventArgs e)
    {
        if (LoginUser(tUser.Text, Password.Text).Result.IsSuccessStatusCode)
        {
            Notifier.Notify("Successfully logged in.. Please wait!");

        }
        else
        {
            Notifier.Notify("Please check your Credential..");
        }            
    }
Run Code Online (Sandbox Code Playgroud)
    public async Task<HttpResponseMessage> LoginUser(string userid, string password)
    {
        string URI = "http://api.danubeco.com/api/userapps/authenticate";

        using (var client = new HttpClient())
        {
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("c291cmF2OmtheWFs");

            using (var response = await client.GetAsync(String.Format("{0}/{1}/{2}", URI, userid, password)))
            {
                return response;
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

请帮忙!

c# asynchronous async-await webapi2 httpresponsemessage

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

HttpContext.Response.OutputStream 在 WebAPI 的 HttpResponseMessage 中使用的替代方法是什么

我正在编写一个用于处理 PDF 文档的 WebAPI。它是在之前实现 IHttpHandler 并使用 HttpContext 获取上下文的 ashx 页面中编写的。我现在正在使用 WebAPI 编写它。在 WebAPI 中,我们有 HttpResponseMessage。对于 HttpContext.Response.BinaryWrite,我们在 HttpResponseMessage 中有新的 ByteArrayContent。但是 WebAPI 中 HttpContext.Response.OutputStream 的替代方案是什么?我需要在 WebAPI 中使用 OutputStram 的替代方案,因为我将此 OutputStream 作为参数传递给另一个 dll。

ashx 中的代码:

SomeReport.PdfReport rpt = new SomeReport.PdfReport(docID);
rpt.CreateReport(context.Response.OutputStream);
Run Code Online (Sandbox Code Playgroud)

asp.net-web-api httpresponsemessage

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

无法转换 Newtonsoft.Json.Linq.JObject 类型的对象,即使我试图转换为具有匹配属性的对象

我正在 VS2017 中使用 ASP.NET Core 2.0。

我正在尝试反序列化一些返回的 JSON,HttpResponseMessage但我收到“无法转换类型的对象...”异常。

这是失败的代码;

FilesUploadedListResponse fileUploadListResponse = new FilesUploadedListResponse();
string jsonResult = response.Content.ReadAsStringAsync().Result;
fileUploadListResponse = (FilesUploadedListResponse)JsonConvert.DeserializeObject(jsonResult);
Run Code Online (Sandbox Code Playgroud)

最后一行是我得到异常的地方......

"Unable to cast object of type 'Newtonsoft.Json.Linq.JObject' to type 'FilesUploadedListResponse'."
Run Code Online (Sandbox Code Playgroud)

这是字符串中的实际 Json jsonResult

"{\"uploadedfiles\":[],\"totalResults\":0,\"pageNumber\":0,\"pageSize\":0}"
Run Code Online (Sandbox Code Playgroud)

uploadedFiles此结果中的数组为空,因为还没有上传的文件,但我认为将其设为空不应创建异常,对吗?如果它不为空,它会有类似这样的响应:

{
 "uploadedFiles": [
 {
 "id": 1,
 "createdTime": "July 10, 2017 02:02:25 PM",
 "filename": "20170710_14022507701.jpg",
 "sentTime": "July 10, 2017 02:05:11 PM",
 "fileSize": "124 KB"
 },
 {
 "id": 2,
 "createdTime": "June 05, 2017 09:39:25 AM",
 "filename": "20170605_093907701.jpg",
 "sentTime": "June 05, 2017 …
Run Code Online (Sandbox Code Playgroud)

json.net json-deserialization c#-7.0 httpresponsemessage asp.net-core-2.0

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

Web API:单独下载多个文件

我有一个 Web Api 控制器方法,可以获取传递的文档 ID,并且它应该为这些请求的 ID 单独返回文档文件。我已尝试通过以下链接接受的答案来实现此功能,但它不起作用。我不知道我哪里做错了。

从单个 WebApi 方法提供多个二进制文件的最佳方法是什么?

我的 Web Api 方法,

   public async Task<HttpResponseMessage> DownloadMultiDocumentAsync( 
             IClaimedUser user, string documentId)
    {
        List<long> docIds = documentId.Split(',').Select(long.Parse).ToList();
        List<Document> documentList = coreDataContext.Documents.Where(d => docIds.Contains(d.DocumentId) && d.IsActive).ToList();

        var content = new MultipartContent();
        CloudBlockBlob blob = null;

        var container = GetBlobClient(tenantInfo);
        var directory = container.GetDirectoryReference(
            string.Format(DirectoryNameConfigValue, tenantInfo.TenantId.ToString(), documentList[0].ProjectId));

        for (int docId = 0; docId < documentList.Count; docId++)
        {
            blob = directory.GetBlockBlobReference(DocumentNameConfigValue + documentList[docId].DocumentId);
            if (!blob.Exists()) continue;

            MemoryStream memStream = new MemoryStream();
            await blob.DownloadToStreamAsync(memStream); …
Run Code Online (Sandbox Code Playgroud)

c# web-applications azure asp.net-web-api2 httpresponsemessage

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

如何在C#中正确检查HttpResponseMessage的http状态代码?

C#报表中的新手

可以说我有以下代码

HttpResponseMessage response = ...
Run Code Online (Sandbox Code Playgroud)

我如何检查状态代码response是否为403?

该属性StatusCode是一个对象-与整数相对,所以我不太确定该怎么做。

c# dotnet-httpclient httpresponsemessage

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