rails post参数截断

时间:2014-06-12 20:54:23

标签: ruby-on-rails ruby post

我有一个奇怪的是我希望有人可以提供帮助,我有一个应用程序正在上传一个相当长的字符串作为post参数,我知道Web请求是正确的,因为它适用于PHP。

使用Rails 4虽然它似乎每次都在同一点上切掉字符串,但是我找不到任何表明这是正常行为的文档,我就像这样分配它:

mystring= params[:post_xml]

如果我执行以下操作:

mystring = request.body.read

一切正常!

有什么想法吗?

编辑为了清楚起见,我的C#请求代码在端口3001上,因为它是rails的测试端口

HttpWebRequest httpWReq =(HttpWebRequest)WebRequest.Create(“http://mydomain.com:3001/api/new”);

        ASCIIEncoding encoding = new ASCIIEncoding();


        var textFromDoc = Globals.ThisAddIn.Application.ActiveDocument.Content.Text;
        // string postData = "content=" + textFromDoc;
        //byte[] data = encoding.GetBytes(postData);

        byte[] data = Encoding.UTF8.GetBytes(textFromDoc);

        httpWReq.Method = "POST";
        httpWReq.ContentType = "text/xml; encoding='utf-8'";
        //"application/x-www-form-urlencoded";
        httpWReq.ContentLength = data.Length;

        using (Stream stream = httpWReq.GetRequestStream())
        {
            stream.Write(data, 0, data.Length);
        }

        HttpWebResponse response = (HttpWebResponse)httpWReq.GetResponse();

        string responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
        System.Windows.Forms.MessageBox.Show(responseString);
    }
    catch (System.Exception excep)
    {
        System.Windows.Forms.MessageBox.Show(excep.Message);
    }

1 个答案:

答案 0 :(得分:0)

ActionController::StrongParameters#paramsActionDispatch::Request#body非常不同。这两种方法有不同的用途。

查看Chapter 4: Parameters中的Action Controller Overview了解详情。