0

我使用 POST 方法将字符串发送到 REST 服务。

 //--------------------------Method Post--------------------------
    public static string methodPost(string header,string url,string body)
    {

        var request = (HttpWebRequest)WebRequest.Create(url);
        request.Method = "POST";
        if(header!=null) request.Headers.Add(header);
        request.ContentType = "application/json";
        byte[] byteArray = Encoding.UTF8.GetBytes(body);
        request.ContentLength = byteArray.Length;

        Stream dataStream = request.GetRequestStream();

        dataStream.Write(byteArray, 0, byteArray.Length);
        dataStream.Close();
        var response = request.GetResponse();

        Stream stream2 = response.GetResponseStream();
        StreamReader reader2 = new StreamReader(stream2);
        String ok = reader2.ReadToEnd();
        return ok;
    }

if string body ="test send string" : 成功,但是 string body ="test send ' string" : 不成功。如何解决?感谢!

4

1 回答 1

0

"test send ' string"是合法的 json,但你可以试试"test send \' string". 如果这不起作用,您需要询问管理 Web 服务的人员。

于 2013-04-27T14:23:03.277 回答