简体   繁体   English

无法让Fiddler使用本地主机不同的端口捕获来自MVC的HttpClient Web API调用

[英]Can't get Fiddler to capture HttpClient web api calls from MVC with localhost different port

Yet another fiddler can't get it to capture post. 另一个提琴手无法获取帖子。

Similar to this SO Post I have spent two hours now reading and trying different solution yet none of them allow me to see my fiddler web api traffic. 与此SO Post类似,我花了两个小时阅读和尝试不同的解决方案,但没有一个使我看到我的提琴手Web api流量。

As a side note my code is working I am just focused on getting fiddler to show me the api calls. 顺便说一句,我的代码正在工作,我只是专注于让提琴手向我展示api调用。

I will describe my setup then what I have tried. 我将描述我的设置,然后再尝试。

My Web API is a separate MVC 6, EF 7 project running on port 63381 我的Web API是在端口63381上运行的单独的MVC 6,EF 7项目

http://localhost:63381/ HTTP://本地主机:63381 /

My ASP.NET MVC 5 web client project is running on port: 59722 我的ASP.NET MVC 5 Web客户端项目在以下端口上运行:59722

http://localhost:59722/ HTTP://本地主机:59722 /

A typical action controller in the mvc client: mvc客户端中的典型动作控制器:

//Controller CTOR
public ClientController()
{
  client = new HttpClient();
  client.BaseAddress = new Uri("http://localhost:63381/api/MyApi");
  client.DefaultRequestHeaders.Accept.Clear();
  client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
}

//Action within ClientController
public async Task<JsonResult> AddNewSubCategory()
{
   HttpResponseMessage responseMessage = await client.PostAsJsonAsync(url2, content);
   if (responseMessage.IsSuccessStatusCode)
   {
     return Json("[{Update Success}]", JsonRequestBehavior.AllowGet);
   }
     return Json("[{Error Updating}]", JsonRequestBehavior.AllowGet);
   }
}
  1. Added the block to 32 & 62 machine.config. 将块添加到32和62 machine.config。 Restarted visual studio did NOT restart machine or any other service. 重新启动Visual Studio中没有重新启动计算机或任何其他服务。 This did not work. 这没有用。

  2. Added the block to the client web.config and this didn't work. 将块添加到客户端web.config中,此操作不起作用。

  3. Changed localhost to machinename:port Specifically I changed http://localhost:63381/api/MyApi to http://gpgvm-pc:63381/api/MyApi 将localhost更改为machinename:port具体来说,我将http:// localhost:63381 / api / MyApi更改http:// gpgvm-pc:63381 / api / MyApi

  4. Modified Global.asax with: 使用以下命令修改了Global.asax:

    ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return true; }); ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate {return true;});

  5. Fiddler custom rules 提琴手自定义规则

  6. Reverse proxy 反向代理

  7. Set fiddler listening on a different port. 设置提琴手在另一个端口上侦听。

At this point I surrender. 至此我投降了。 It seems to me #1 should work to capture everything but I am obviously still doing something wrong because I can get fiddler to capture one or the other but NOT the client calling off to the client??? 在我看来,#1应该可以捕获所有内容,但是显然我仍然在做错什么,因为我可以让提琴手捕获一个或另一个,而不是客户端取消向客户端的请求???


Update: 更新:

My machine locked and after reboot I started seeing the api calls so this issue was something with my machine. 我的机器被锁定,重新启动后,我开始看到api调用,所以这个问题与我的机器有关。 So sorry to bother. 很抱歉打扰。

The problem is most likely that you are using localhost which are handled in a special way. 问题很可能是您使用以特殊方式处理的本地主机。

Try using machine name or your ip instead (do not use 127.0.0.1). 尝试使用计算机名称或您的IP(不要使用127.0.0.1)。

The documentation have information about this as well: 该文档也包含有关此信息:

http://docs.telerik.com/fiddler/Observe-Traffic/Troubleshooting/NoTrafficToLocalhost http://docs.telerik.com/fiddler/Observe-Traffic/Troubleshooting/NoTrafficToLocalhost

If you try to hit specific action in api then use that code in webapi config 如果您尝试在api中执行特定操作,则在webapi配置中使用该代码

public static void Register(HttpConfiguration config)

        {
            //config.Routes.MapHttpRoute(
            //    name: "DefaultApi",
            //    routeTemplate: "api/{controller}/{id}",
            //    defaults: new { id = RouteParameter.Optional });

           config.Routes.MapHttpRoute("API Default", "api/{controller}/{action}/{id}",
           new { id = RouteParameter.Optional });

        }

This code where u call your api. 您在其中调用您的api的这段代码。

 public ActionResult ClientController(model content)

        {
            try
            {
                HttpClient client = new HttpClient("http://localhost:63381/");
                client.BaseAddress = new Uri();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                HttpResponseMessage response = client.PostAsJsonAsync("api/MyApi/url2", content).Result;
                if (response.IsSuccessStatusCode)
                {
                    return Json(new { code = 0, message = "Success" });
                }
                else
                {
                    return Json(new { code = -1, message = "Failed" });
                }
            }
            catch (Exception ex)
            {
                int code = -2;
                return Json(new { code = code, message = "Failed" });
            }
        }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM