小编mgi*_*ota的帖子

为什么只有在我打开Fiddler时才能在ASP.NET中调用API?

我在我的索引控制器中调用这样的API,一切正常,只有我打开Fiddler.

public ActionResult Index()
{
    Base model = null;
    var client = new HttpClient();
    var task =
        client.GetAsync(
        "http://example.api.com/users/john/profile")
        .ContinueWith((taskwithresponse) =>
        {
            var response = taskwithresponse.Result;
            var readtask = response.Content.ReadAsAsync<Base>();
            readtask.Wait();
            model = readtask.Result;
        });
    task.Wait();

    return View(model);
}
Run Code Online (Sandbox Code Playgroud)

如果我关闭Fiddler我会收到以下错误:

无法建立连接,因为目标计算机主动拒绝它127.0.0.1:8888

是否有一些配置,我必须包括,以便调用API工作,即使我没有Fiddler打开.

c# asp.net fiddler asp.net-web-api

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

字符串到int formatexception

在PHP我可以做这样的事情:

if (balance == 0 && !neverBought)
Run Code Online (Sandbox Code Playgroud)

余额来自API,是一个字符串.

在C#中,我尝试将balance转换为int,如下所示:

if (int.Parse(balance) == 0 && !(neverBought))
Run Code Online (Sandbox Code Playgroud)

但是我得到了异常详细信息:System.FormatException:输入字符串的格式不正确.

我究竟做错了什么?

.net c#

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

标签 统计

c# ×2

.net ×1

asp.net ×1

asp.net-web-api ×1

fiddler ×1