我在我的索引控制器中调用这样的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打开.
在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:输入字符串的格式不正确.
我究竟做错了什么?