2 qq 25210351 qq_25210351 于 2017.08.28 12:03 提问

大神帮我看下这个post方法有什么问题

public static string HttpPost(string url, string param)
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.Accept = "*/*";
request.Timeout = 15000;
request.AllowAutoRedirect = false;

        StreamWriter requestStream = null;
        WebResponse response = null;
        string responseStr = null;

        try
        {
            requestStream = new StreamWriter(request.GetRequestStream());
            requestStream.Write(param);
            requestStream.Close();

            response = request.GetResponse();
            if (response != null)
            {
                StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
                responseStr = reader.ReadToEnd();
                reader.Close();
            }
        }
        catch (Exception)
        {
            throw;
        }
        finally
        {
            request = null;
            requestStream = null;
            response = null;
        }

        return responseStr;
    }

4个回答

qq_25210351
qq_25210351   2017.08.28 12:05

这个 try 里面 出现了问题 但是日志文件 没写出来 大神帮我看下 这方法哪里可能出问题

qq_25210351
qq_25210351   2017.08.28 12:06

param参数 很大

qq_34658785
qq_34658785   2017.08.28 13:36

厄,在catch里面写throw,抓取异常后又抛出,这是什么操作,你可以在catch里面用 传进来的异常对象调用print方法,应该就可以看到异常日志了

liugstick
liugstick   2017.08.28 14:34

close应该final里面

Csdn user default icon
上传中...
上传图片
插入图片