发送POST请求通过ASP.NET MVC提琴手行动 [英] Send POST request to asp.net mvc action via Fiddler

查看:139
本文介绍了发送POST请求通过ASP.NET MVC提琴手行动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 ASP.NET MVC 网​​站。我的一个途径是网​​址这需要5个参数。为了说明起见,这些参数被命名为参数1 参数2 参数3 parameter4 parameter5 。目前,我正在兴建一些 C# code一个网址,将 POST 来通过MVC的行动 Web客户端。即code是这样的:

I have an ASP.NET MVC web site. One of my routes is a URL that takes 5 parameters. For the sake of illustration, these parameters are named parameter1, parameter2, parameter3, parameter4, and parameter5. Currently, I'm constructing a URL in some C# code that will POST to the mvc action via a WebClient. that code looks like this:

WebClient myWebClient = new WebClient();
myWebClient.UploadStringCompleted += myWebClient_UploadStringCompleted;

string url = "http://www.example.com/customer/" + parameter1 + "/orders/" + parameter2 + "/" + parameter3 + "/" + parameter4 + "/" + parameter5;
myWebClient.UploadStringAsync(new Uri(url, UriKind.Absolute));

我相信,在 UploadString 方法做了 POST 。我需要做一个 POST ,因为我的参数值可能会很长。事实上,我估计,偶尔,总的URL长度可能是20000个字符。无论如何,我收到了 400错误当我尝试后我的数据。在努力调试此,我想弄清楚如何模拟 POST 提琴手

I'm confident that the UploadString method does a POST. I need to do a POST, because my parameter values can be very long. In fact, I estimate that occasionally, the total url length may be 20000 characters long. Regardless, I get a 400 error when I attempt to post my data. In an effort to debug this, I'm trying to figure out how to simulate a POST in Fiddler.

假设我是通过一个查询字符串如上所示传递的价值观,我进入提琴手什么样的​​价值观?从作曲设置页,我不知道该怎么对请求头区域中输入。我也不能完全肯定什么为URL输入。我不知道如果我把整个URL在那里,包括参数值,或者如果这些属于在请求头

Assuming that I am passing values via a query string as shown above, what values do I enter into Fiddler? From the Composer tab, I'm not sure what to enter for the Request Headers area. I'm also not entirely sure what to enter for the url. I'm not sure if I put the entire URL in there, including the parameter values, or if those belong in the Request Headers.

我需要进入提琴手,这样我可以调试我的问题?

What I need to enter into Fiddler, so that I can debug my issue?

推荐答案

基本上所有的参数都是URL的一部分,这是你的问题的根源。这里是正在发生的事情:你打的URL长度的限制,并收到400错误的请求的错误。在现实世界中大多数Web浏览器不使用URL超过2000个字符长的工作。

Basically all your parameters are a part of the URL, and this is the root of your problem. Here is what is going on: you are hitting the URL length limitation, and receiving a "400 Bad request" error. In real world most web browsers do not work with URLs more than 2000 characters long.

要解决这个问题,我建议做一点重构,使请求被提交到网址 http://www.example.com/customer/parameter1/orders 甚至 http://www.example.com/customer/orders 与参数请求体发送。下面是如何测试小提琴手这样的要求:

To resolve this problem I would suggest doing a bit of refactoring, so that request is posted to the URL http://www.example.com/customer/parameter1/orders or even http://www.example.com/customer/orders with parameters send in request body. Here is how test such request in Fiddler:


  1. 作曲选项卡中选择 POST 请求动词

  2. 指定URL为

  1. On Composer tab choose POST request verb
  2. Specify the URL as

<一个href=\"http://www.example.com/customer/parameter1/orders\">http://www.example.com/customer/parameter1/orders

http://www.example.com/customer/orders

请求头部分,您可以设置内容类型头像

In Request Headers section you can set content type header like

Content-Type: application/x-www-form-urlencoded

或你可能需要的任何其他头。或让它空白,将工作你的情况。

or any other header you might require. Or just leave it blank which will work in your case.

最后,在请求体字段列表中查询字符串形式的参数

Finally in Request Body field list your parameters in query string form

parameter1name=parameter1value&parameter2name=parameter2value


在这里新情况是如何使用发送此类请求 Web客户端

In this new case here is how you can send such a request using WebClient:

WebClient myWebClient = new WebClient();
myWebClient.UploadStringCompleted += myWebClient_UploadStringCompleted;

string url = "http://www.example.com/customer/orders";
string data = "parameter1name=parameter1value&parameter2name=parameter2value";

myWebClient.UploadStringAsync(new Uri(url, UriKind.Absolute), data);

这篇关于发送POST请求通过ASP.NET MVC提琴手行动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆