简单的卷曲请求失败 - 为什么?

时间:2016-03-02 15:59:23

标签: curl express

我正在关注一个代码学校项目,虽然这个curl命令为教师提供了JSON(当我从浏览器点击它时路由提供JSON),但它在我的终端中失败了。它甚至没有击中路线!

using (var client = new HttpClient())
{
    var formFields = new List<KeyValuePair<string, string>>();

    formFields.Add(new KeyValuePair<string, string>("AccountId", _dealerAccountId));
    formFields.Add(new KeyValuePair<string, string>("Username", _dealerUsername));
    formFields.Add(new KeyValuePair<string, string>("Password", _dealerPassword));

    var formContent = new FormUrlEncodedContent(formFields);
    var response = await client.PostAsync(httpPrefix + "://" + httpHost + "/WebApi/Token/GetToken_v1/1592673/", formContent);
    if (!response.IsSuccessStatusCode)
    {
        return;
    }
    var responseContent = await response.Content.ReadAsStringAsync();

    token = JsonConvert.DeserializeObject<string>(responseContent);
}

相关路线(快递中)是

OlympicsMEAN [master] :> curl -i localhost:8181/sports
HTTP/1.1 303 See Other
X-Powered-By: Express
Content-Type: text/html; charset=UTF-8
Content-Length: 47
X-Content-Type-Options: nosniff
Location: /sports/
Date: Wed, 02 Mar 2016 15:43:35 GMT
Connection: keep-alive

Redirecting to <a href="/sports/">/sports/</a>

我甚至试过这个......结果相同

app.get("/sports", (request, response) => {
  console.log('hit /sports endpoint');
  response.json( ['Cycling', 'Waitlyfting'] );
});

我以为我处理了CURL。当路由通过浏览器请求正常工作时,它可能会失败的原因是什么?

1 个答案:

答案 0 :(得分:1)

不确定我真的得到了你想要的东西,
但如果你的意思是curl返回你指定的URL“后面”的内容, 那么你可能需要一个“-L”选项。

你从curl调用中给出的结果表示300代码, 常规浏览器只会跟随“位置”标题中的新位置, 而curl只有在“-L”生效时才会这样做。

相关问题