soitgoes / LoveSeat

Bringing CouchDB and .NET little closer
Other
96 stars 50 forks source link

Special characters not working in update function. #42

Closed Rameshvenkat closed 11 years ago

Rameshvenkat commented 11 years ago

I am trying to insert special characters from UI into couchdb. but while returning response it produces Server Error:500 .Please help me to fix this issue. Thanks in advance. See following code for reference.

public ReVO Update(ReVO atvo) { ReVO response = new ReVO (); Stream newStream = null; WebResponse webResponse = null; try { string data = string.Empty;

            //data = JsonConvert.SerializeObject(atvo);

            data = "Obj=" + JsonConvert.SerializeObject(atvo);
            byte[] dataStream = Encoding.UTF8.GetBytes(data);

            request = ConfigSettings.GetEnvConfigValue("CouchDBUrl") + "/_design/At/_update/updateAtDetail/" + atvo.AtDocId;

            Uri requestUri = new Uri(request);
            WebRequest webRequest = WebRequest.Create(requestUri);
            webRequest.Method = "POST";
            webRequest.ContentType = "application/x-www-form-urlencoded";
            webRequest.ContentLength = dataStream.Length;

            newStream = webRequest.GetRequestStream();
            // Send the data. 
            newStream.Write(dataStream, 0, dataStream.Length);
            webResponse = webRequest.GetResponse();
            response.StatusCode = "1";
            response.StatusMessage = "Updated Successfully";
            response.AtId = atvo.AtDocId;

} }

soitgoes commented 11 years ago

The way that you are using this is basically trying to do everything yourself. If you would just use LoveSeat then you shouldn't have this problem.

The request and response are there for reference if you need them but they don't have to be used at all.

On Mon, Dec 10, 2012 at 12:28 AM, Rameshvenkat notifications@github.comwrote:

I am trying to insert special characters from UI into couchdb. but while returning response it produces Server Error:500 .Please help me to fix this issue. Thanks in advance. See following code for reference.

public ResponseVO Update(ReVO assetvo) { ResponseVO response = new ResponseVO(); Stream newStream = null; WebResponse webResponse = null; try { string data = string.Empty;

        //data = JsonConvert.SerializeObject(assetvo);

        data = "assetObj=" + JsonConvert.SerializeObject(assetvo);
        byte[] dataStream = Encoding.UTF8.GetBytes(data);

        //string request = ConfigurationManager.AppSettings["CouchDBUrl"].ToString() + "/_design/Asset/_update/updateAssetDetail/" + assetvo.AssetDocID;

        string request = ConfigSettings.GetEnvConfigValue("CouchDBUrl") + "/_design/Asset/_update/updateAssetDetail/" + assetvo.AssetDocId;

        Uri requestUri = new Uri(request);
        WebRequest webRequest = WebRequest.Create(requestUri);
        webRequest.Method = "POST";
        webRequest.ContentType = "application/x-www-form-urlencoded";
        webRequest.ContentLength = dataStream.Length;

        newStream = webRequest.GetRequestStream();
        // Send the data.
        newStream.Write(dataStream, 0, dataStream.Length);
        webResponse = webRequest.GetResponse();
        response.StatusCode = "1";
        response.StatusMessage = "Updated Successfully";
        response.AssetId = assetvo.AssetDocId;

} }

— Reply to this email directly or view it on GitHubhttps://github.com/soitgoes/LoveSeat/issues/42.

Martin Murphy Whiteboard-IT http://whiteboard-it.com w: (205) 588-7102