Can we use Json to post text1 and text2 parameter instead of query string?

44 views
Skip to first unread message

webzeb...@gmail.com

unread,
Jul 23, 2018, 6:25:20 AM7/23/18
to Dandelion Support Forum
I want to get similarity between two paragraphs so not able to pass that through URL. So I am looking for method to post that two paragraph to check there similarity.

I am using C#. Below is my sample code that I suppose to work.

private static string GetSimilarityBydandelion(string oristr, string writtenstr)
    {
        var result = string.Empty;
        var myRequest = (HttpWebRequest)WebRequest.Create("https://api.dandelion.eu/datatxt/sim/v1/?token={MyToken}");
        myRequest.ContentType = "application/json";
        myRequest.Method = "POST";

        using (var streamWriter = new StreamWriter(myRequest.GetRequestStream()))
        {
            string json = "{\"text1\":\"" + oristr + "\"," +
            "\"text2\":\"" + writtenstr + "\"}";

            streamWriter.Write(json);
            streamWriter.Flush();
            streamWriter.Close();
        }

        var ApiResponse = (HttpWebResponse)myRequest.GetResponse();
        using (var streamReader = new StreamReader(ApiResponse.GetResponseStream()))
        {
            result = streamReader.ReadToEnd();
        }
        return result;
    }

san...@dandelion.eu

unread,
Jul 23, 2018, 8:37:21 AM7/23/18
to Dandelion Support Forum
Hi,

can you report the error code and the error message returned in the response?

Cheers,

Roberto Santoro
Dandelion API team

webzeb...@gmail.com

unread,
Jul 24, 2018, 1:54:57 AM7/24/18
to Dandelion Support Forum
Hi Roberto,

I get this error when I try to get similarity between two paragraphs having length more than 100 words.

The remote server returned an error: (414) Request URI Too Long.

Thanks

san...@dandelion.eu

unread,
Jul 26, 2018, 9:37:49 AM7/26/18
to Dandelion Support Forum
Ok, this error generally happens when the two texts are sent in the query string, and they are longer than the query string character limit.
Sending them in the body should solve your problem.
Message has been deleted

webzeb...@gmail.com

unread,
Jul 30, 2018, 7:05:26 AM7/30/18
to Dandelion Support Forum
I am not able to pass text1 and text2 using form data, It gives me below error. I also tried this with postman.and I have attached the result screen shot for that as well.

{
    "message": "Parameter [text1|html1|url1|html_fragment1] not found",
    "code": "error.missingParameter",
    "data": {
        "parameter": "text1|html1|url1|html_fragment1"
    },
    "error": true
}

Azim Hawaldar

unread,
Jul 30, 2018, 7:14:20 AM7/30/18
to Dandelion Support Forum
You should pass data in x-www form url encoded. Not the form data
Reply all
Reply to author
Forward
0 new messages