无法读取网页API POST主体数据(Cannot read body data from web api POST)

   IT问题网   2018-12-24 00:00:00

问 题

我想提取一些数据在新asp.net的web api使用的一种要求。我有一个处理程序设置是这样的:

 公共类mytesthandler:delegatinghandler
{
保护覆盖system.threading.tasks.task htt的presponsemessage sendasync(htt的prequestmessage要求,system.threading.cancellationtoken的cancellationtoken)
{
如果(request.content.isformdata())
{
。request.content.readasstreamasync()continuewith(x = {
var的结果="";
使用(var sr =新的streamreader(x.result))
{
结果= sr.readtoend();
}
console.write(结果);
});
}

返回base.sendasync(请求的cancellationtoken);
}
}
 

这是我的http请求:

post http://127.0.0.1/test http / 1.1
连接:保持活动
内容长度:29
内容类型:应用程序/ x-www的形式urlen coded
期望:100-继续
主持人:127.0.0.1

my_property = my_value
 

问题是,无论我如何努力读取 request.content 的信息,它总是空的。我试过

request.content.readasstreamasync
request.content.readasformdataasync
request.content.readas formdatacollection
 

以及

[httpget,httppost]
公共字符串指数([frombody]字符串my_property)
{
// my_property == null
返回"测试";
}
 

如果它工作无。我不能得到的数据带出体外。我主持的内部iis的windows 7和使用招提交请求。我究竟做错了什么?

解决方案

现在的问题是,随着网络的api身体只能读一次。我有一个http模块的运行被登记请求的所有细节,并正在读通过身体。

标签:无法没法读取网页主体数据



分享:

  • 微信
  • QQ好友
  • QQ空间
  • 新浪微博


热门推荐

我如何推断括号的使用翻译的前pression树是什么时候?(How do I infer the usage of parentheses when translating an expression tree)

problem i am working on translating an expression tree to ...

开发一个简单的Windows系统托盘桌面应用程序消耗.NET Web服务(Developing a simple Windows system tray desktop app to consume a .NET web service)

problem i'm required to develop a simple windows system t ...

在什么条件下可以一个线程进入一个锁(监视器)区不止一次同时?(Under what conditions can a thread enter a lock (Monitor) region more than once concurrently)

problem (question revised): so far, the answers all inclu ...

DELETE语句冲突与实体框架相同的表引用约束(The DELETE statement conflicted with the SAME TABLE REFERENCE constraint with Entity Framework)

problem i have a table with a self reference where the pa ...

不可变字典VS字典VS C5 VS F# - 性能(Immutable Dictionary Vs Dictionary Vs C5 Vs F# - performance)

problem our application uses plenty of dictionaries which ...

如何在WPF中绘制数字信号?(How to draw digital signal in WPF)

problem i need to draw digital signal and be able to move ...

谁拥有.NET包流(如TextWriter的)?(Who owns wrapped streams (e.g. TextWriter) in .NET)

problem i've recently encountered an error "o ...

Object等 - 什么纯粹的对象或引用类型不重写等于基本逻辑?(Object Equals - whats the basic logic for pure objects or reference types that don't override Equals)

problem i got here after reading this and i didn't find a ...

在串实习和替代品(On string interning and alternatives)

problem i have a large file which, in essence contains da ...

交货.NET 3.5 SP1(Delivery of .Net 3.5 SP1)

problem if i were to include .net framework setup file al ...

如何隐藏一个控制台应用程序用户界面使用的Process.Start什么时候?(How do I hide a console application user interface when using Process.Start)

problem i want to run a console application t ...

Visual C#中的Mac电脑(Visual C# for Macs)

problem is there a c# compiler for macs that ...

如何才能知道一个对象的类型是IEnumerable的℃的子类; T任何值类型T?(How do I find out whether an object's type is a subclass of IEnumerable<T> for any value type T)

problem i need to validate an object to see w ...

Web服务发现在WCF:WS-发现或UDDI?(Web service discovery in WCF : Ws-Discovery or UDDI)

problem i know the distinction between uddi and ws-discov ...

有什么方法可以解决C#内存泄漏(What are ways to solve Memory Leaks in C#)

problem i'm learning c#.from what i know, you have to set ...

T>使用DataContext.ExecuteQuery&LT时忽略只读类属性;(Ignore read-only class properties when using DataContext.ExecuteQuery<T>)

problem how do i tell a linq data context to ignore eithe ...

什么是多线程应用程序使用的是辛格尔顿的危险(What are the Dangers of using a Singleton in a multithreaded application)

problem i'm looking at using a singleton in a multithread ...

System.BadImageFormatException:如何修复.NET版本不匹配?(System.BadImageFormatException: How to fix .NET version mismatch)

problem i wrote a dll in vs 2005 that will be ...

C#的XMLDocument到数据表?(C# XMLDocument to DataTable)

problem i assume i have to do this via a dataset, but it ...

得分/评级引擎 - 咨询和例子?(Scoring / rating engines - advice and examples)

problem i need to create a flexible (and preferably dynam ...