请问在.NET WebAPI的开发中,如何使用httpcontext.request?

tudoushaopaigu 2014-11-07 10:03:10
别人POST调用接口,我想把POST过来的所有数据都先打在日志里,然后再进行处理。以前ashx中我可以用
context.Request.Form.Tostring()

但在web api的contrler中没法这样使用啊,这里的Request不是httpcontext下面的request。。。
...全文
1575 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
习惯、单调 2016-12-29
  • 打赏
  • 举报
回复
楼主问题解决了没?我也碰到了类似的问题 有没有解决方案 在webapi中使用 httpContext httpRequest
tudoushaopaigu 2014-11-10
  • 打赏
  • 举报
回复
引用 4 楼 jun471537173 的回复:
断点调试下,我复制了你上面的代码,调试是可以的

jun471537173 2014-11-07
  • 打赏
  • 举报
回复
断点调试下,我复制了你上面的代码,调试是可以的
tudoushaopaigu 2014-11-07
  • 打赏
  • 举报
回复
引用 2 楼 jun471537173 的回复:
            Stream stream = Stream.Null;
            HttpContent content = this.Request.Content;
            Task readTask = content.ReadAsStreamAsync().ContinueWith((task) => { stream = task.Result; });
            readTask.Wait();

            string data = string.Empty;
            using (StreamReader reader = new StreamReader(stream))
            {
                data = reader.ReadToEnd();
            }
没用啊

    function test1() {
        $.ajax({
            url: "http://localhost:27920/api/test",
            type: "post",
            cache: false,
            data:{ text:"dfas"},
            success:function(rs){
                alert(rs);
            }
        })
    }
后台我找你给的方法写的,data最后还是"" , 至少应该能获取到 text=dfas 啊
jun471537173 2014-11-07
  • 打赏
  • 举报
回复
            Stream stream = Stream.Null;
            HttpContent content = this.Request.Content;
            Task readTask = content.ReadAsStreamAsync().ContinueWith((task) => { stream = task.Result; });
            readTask.Wait();

            string data = string.Empty;
            using (StreamReader reader = new StreamReader(stream))
            {
                data = reader.ReadToEnd();
            }
milozy1983 2014-11-07
  • 打赏
  • 举报
回复
引用System.web然后再用可以不,我虽然没这样用过,但感觉如果都是在同一个mvc项目下应该可以用吧。
2.ASP.NET.2.0.高级编程(第4版) [1/7] 原书名: Professional ASP.NET 2.0 原出版社: Wrox 作者:(美)Bill Evjen, Scott Hanselman, Farhan Muhammad [同作者作品] [作译者介绍] 译者: 李敏波[同译者作品] 出版社:清华大学出版社 ISBN:7302139067 上架时间:2006-11-16 出版日期:2006 年11月 开本:185×260 页码:1090 版次:4-1 内容简介回到顶部↑本书全面介绍了ASP.NET各种编程技能和2.0版的巨大变化,并详细阐述了2.0版的每个新特性。书提供了大量的实例,可帮助读者快速掌握如何在.NET平台下开发功能强大的ASP.NET应用程序。本书适合有一些基础的ASP.NET初级程序员以及准备迁移到ASP.NET 2.0的编程老手。该书与《ASP.NET 2.0入门经典(第4版)》及其早期版本,曾影响到无数Web程序员。. ASP.NET允许Web站点为每个访问者显示独一无二的页面,而不是显示相同的静态HTML页面。ASP.NET 2.0的发布,使Web应用程序的开发又前进了一大步。这个新版本增加了大量的新功能,减少了编写常见应用程序所需的代码量。 ASP.NET 2.0新增了50多个新服务器控件,类的数量也翻了一倍,其他许多方面也有很大的变化。本书介绍了ASP.NET 2.0的每个新增特性和功能,以便读者把这些新技术应用于实践。.. 本书主要内容 ● 服务器控件的概念及其在ASP.NET开发的主导作用 ● 使用新的Master页面特性创建模板化的ASP.NET页面 ● 调试和处理错误的技术 ● 提取、创建、处理和存储XML的各种框架 ● 打包和部署ASP.NET应用程序的方法 ● 快速、逻辑地检索、更新和删除数据 本书读者对象 本书适合于有一些ASP.NET基础知识的学习者以及准备迁移到ASP.NET 2.0的有经验的程序员和开发人员。 目录回到顶部↑ 第1章 ASP.NET 2.0概述 1 1.1 简史 1 1.2 ASP.NET 2.0的目标 2 1.2.1 开发人员的效率 3 1.2.2 管理 5 1.2.3 性能和可伸缩性 8 1.3 ASP.NET 2.0的其他新特性 8 1.3.1 新的开发人员体系结构 8 1.3.2 新的编译系统 12 1.3.3 页面框架的新增内容 13 1.3.4 访问数据的新对象 15 1.3.5 新的服务器控件 15 1.4 建立ASP.NET 2.0页面的新IDE 16 1.5 小结 17 第2章 Visual Studio 2005 19 2.1 启动页面 19 2.2 文档窗口 20 2.2.1 文档窗口的视图 20 2.2.2 标记导航器 21 .2.2.3 页面标签 22 2.2.4 代码改变状态的通知 23 2.2.5 错误通知和辅助 23 2.3 工具箱 25 2.4 Solution Explorer 26 2.5 Server Explorer 28 2.6 Properties窗口 28 2.7 丢失的窗口 29 2.8 其他常见的Visual Studio操作 29 2.8.1 创建新项目 29 2.8.2 引用其他对象 30 2.8.3 使用智能标记 32 2.8.4 保存和导入Visual Studio设置 32 2.8.5 验证HTML 34 2.8.6 团队的合作 36 2.8.7 使用代码片断 36 2.9 小结 38 第3章 应用程序和页面框架 39 3.1 应用程序的位置选项 39 3.1.1 内置的Web服务器 39 3.1.2 IIS 40 3.1.3 FTP 41 3.1.4 Web站点需要FrontPage Extensions 42 3.2 ASP.NET页面结构选项 43 3.2.1 内置编码 44 3.2.2 新的后台编码模型 46 3.3 ASP.NET 2.0的Page指令 48 3.3.1 @Page 49 3.3.2 @Master 51 3.3.3 @Control 52 3.3.4 @Import 53 3.3.5 @Implements 54 3.3.6 @Register 55 3.3.7 @Assembly 55 3.3.8 @PreviousPageType 56 3.3.9 @MasterType 56 3.3.10 @OutputCache 56 3.3.11 @Reference 57 3.4 ASP.NET页面的事件
Scott Worley Publisher: New Riders Publishing First Edition November 15, 2001 ISBN: 0-7357-1135-6, 730 pages Inside ASP.NET Here’s what reviewers are saying about Inside ASP.NET: About the Author Contributing Authors About the Technical Reviewers Acknowledgments Tell Us What You Think! Introduction Who Is This Book For? Contents of the Book I: Introducing ASP.NET 1. An Overview of ASP.NET ASP.NET The .NET Base Class Libraries ASP.NET Web Application Configuration Session and State Management Cache Management ASP.NET Web Application Development Layers Web Forms XML Web Services COM/COM+ Interoperability and Component Services ADO.NET Migration from Classic ASP to ASP.NET Globalization and Localization Enhanced Security 2. Developing Applications with ASP.NET Application Settings Files The Page Syntax Commonly Used Objects and Classes in ASP.NET Tracing ASP.NET Applications ASP.NET Migration Issues Summary 3. Configuring ASP.NET Applications Deploying the web.config Configuration File Using the Configuration Section Analyzing the system.web Configuration Sections Summary II: Core ASP.NET 4. Web Form-Based Development Introduction to Web Forms Web Form Architecture Separating Code from the User Interface Server Controls Validation Controls Summary 5. State Management in ASP.NET What Is State Management? Using ASP.NET Application State Management Summary III: ASP.NET and Data Access 6. Using ADO.NET in ASP.NET Applications Data Access from a Web-Based Perspective ADO and ADO.NET Working with the Main ADO.NET Objects Building Data-Oriented Web Forms Transaction-Enabled ASP.NET Applications Summary 7. Using XML in ASP.NET Applications XML Document Structure How XML Is Used in ASP.NET Other XML Technologies Using XML in Your Application Real-World Examples Summary IV: Advanced Technologies 8. XML Web Service Development in ASP.NET Introduction to XML Web Services Using the SOAP Toolkit with XML Web Services XML Web Service Discovery—Advertising Your Service Using an XML Web Service in ASP.NET Pages Summary 9. Securing ASP.NET Applications Overview of ASP.NET Security Features Applying Security in ASP.NET Applications Inside ASP.NET Security Other Security Considerations Summary 10. Using Component Services with ASP.NET What Are Component Services? Applying Component Services in an ASP.NET Application The business Object Using the business Object Serviced Components Summary 11. Using Messaging Services with ASP.NET Introduction to Messaging Systems Managing MSMQ Message Queues with Windows 2000 Architecture of the .NET Messaging Services Accomplishing Tasks Using MSMQ and .NET Summary 12. Using Directory Services with ASP.NET Introducing Directory Services How Does Active Directory Work? The Benefits of Active Directory Active Directory Technology Summary Summary 13. Localizing and Globalizing ASP.NET Applications What Is Localization? Localizing an ASP.NET Web Application Summary V: Advanced Web Forms 14. Cache Control in ASP.NET ASP.NET Cache Management Page Output Caching Fragment Caching (Partial Page Caching) Request Caching Summary 15. Creating User and Custom Controls for ASP.NET User Controls Introduction to Custom Controls Summary 16. Mobile Device Development with ASP.NET Wireless Application Protocol (WAP) Wireless Markup Language (WML) Enter ASP.NET Summary VI: Putting It All Together 17. Putting It All Together What Is ProjectPal? Installing the ProjectPal Application A Brief Application Walkthrough Application Architecture ProjectPal Service Layers ProjectPal Client Interfaces The ProjectPal Database The ProjectPal Components Inside the ProjectPal Code Summary VII: Appendixes A. An Overview of .NET Multiple Development Platforms Multiple Development Languages .NET Base Class Libraries Common Language Runtime (CLR) Common Type System (CTS) .NET Server Products B. ASP.NET Common Object Reference HttpContext Object (Context Intrinsic Control) The HttpApplication Class The HttpApplicationState Class (Application Intrinsic Object) The HttpSessionState Class ( Session Intrinsic Object) The HttpRequest Class (Request Intrinsic Object) The HttpResponse Class (Response Intrinsic Object) The Server Class ( HttpServerUtility ) SMTPMail API C. ADO Common Object Reference DataSet Object DataTable Object DataColumn Object DataRow Class DataRelation Object DataView Object DataRowView Class OLEDBDATA Objects SQLData … Objects D. HTML Server Control Reference HtmlForm Object— < form> Element HtmlInputText Object— < input> Element HtmlInputHidden Object— < input type=“hidden”> Element HtmlInputCheckbox Object— < input type=”checkbox”> Element HtmlInputRadioButton Object— < input type=“radiobutton”> Element HtmlInputFile Object— < input type=“file”> Element HtmlTextArea Object— < textarea> Element HtmlButton Object— < button> Element HtmlInputButton Object— < input type=“button”> Element HtmlAnchor Object— < a> Element HtmlImage Object— < img> Element HtmlInputImage Object— < input type=“image”> Element HtmlSelect Object— < select> and

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧