.net如何通过Http Post请求发送Json对象数据

.net如何通过Http Post请求发送Json对象数据,在地址栏中要如何输入这些传入的数据

1个回答

public static string getJson(string getUrl)
{
ServicePointManager.ServerCertificateValidationCallback += RemoteCertificateValidate;//处理post https证书验证问题

    string result = "";
    WebRequest req = WebRequest.Create(getUrl);
    req.Method = "POST";
    WebResponse res = req.GetResponse();
    Stream receiveStream = res.GetResponseStream();
    Encoding encode = Encoding.GetEncoding("utf-8");
    StreamReader sr = new StreamReader(receiveStream, encode);

    char[] readbuffer = new char[256];
    int n = sr.Read(readbuffer, 0, 256);
    while (n > 0)
    {
        string str = new string(readbuffer, 0, n);
        result += str;
        n = sr.Read(readbuffer, 0, 256);
    }
    return result;
}

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问