比较响应的状态代码

时间:2018-03-10 20:41:27

标签: f#

我收到一条错误,指出此表达式的结果被隐式忽略。考虑使用ignore来明确地丢弃这个值...不知道这里有什么问题?

let makeRequest url =  

    let request = WebRequest.Create(url) :?> HttpWebRequest
    request.Method <- "POST"
    request.ContentType <- "application/x-www-form-urlencoded"
    request.Accept <- "application/json;charset=UTF-8"
    request.ContentLength <- (int64)data.Length

    use requestStream = request.GetRequestStream() 
    requestStream.Write(data, 0, (data.Length))
    requestStream.Flush()
    requestStream.Close()
    let response = request.GetResponse() :?> HttpWebResponse

    if response.StatusCode = HttpStatusCode.OK then // error here
        "success"
    else 
        "fail"

调用

makeRequest "http://example.co"

1 个答案:

答案 0 :(得分:3)

你的函数makeRequest返回一个字符串并调用

makeRequest "http://example.co"

对返回值没有任何作用。如果您将通话更改为

makeRequest "http://example.co" |> ignore

然后忽略返回值。