In My SCA, I need to sent one Json request with ContentType as text/plain

Hi ,

I need to make a SCA call with Json message and ContentType as text/plain. I tried to change it in show row details. But While calling it is automatically coming as Content-Type: application/json; charset=utf-8. How to overcome this?

  • WebRequest request = WebRequest.Create("##url/"+sv.GetOrCreate(x => x.Request.JSONRequest).id);
                // Set the Method property of the request to POST.
                request.Method = "POST";
                var token= sv.GetOrCreate(x => x.Request.JSONRequest).token;
                request.Headers.Add("Authorization""Bearer " + token);
                //request.RequestUri=sv.GetOrCreate(x => x.Request.JSONRequest).id;
                string postData = "##JSON##;
                byte[] byteArray = Encoding.UTF8.GetBytes(postData);
                request.ContentType = "text/plain";
                // Set the ContentLength property of the WebRequest.
                // Get the request stream.
                Stream dataStream = request.GetRequestStream();
                // Write the data to the request stream.
                dataStream.Write(byteArray, 0, byteArray.Length);
                // Close the Stream object.

                // Get the response.
                WebResponse response = request.GetResponse();
                // Display the status.

                // Get the stream containing content returned by the server.
                // The using block ensures the stream is automatically closed.
                using (dataStream = response.GetResponseStream())
                    // Open the stream using a StreamReader for easy access.
                    StreamReader reader = new StreamReader(dataStream);
                    // Read the content.
                    string responseFromServer = reader.ReadToEnd();
                    // Display the content.

    I tried some code. But getting 401. Could you please provide some sample code? I need to add Authorization header and uri path.

  • I can't see any issue with the script, but I can't investigate just from the pasted portion of it and the screenshot. I guess the content type may be overridden in a rule with a higher priority, but I would have to see your project to provide any meaningful hints.

  • How can I connect with you for 15min to solve this issue?

  • Hi Clea,

    this is a public SV community where anyone can ask for SV help and anyone can answer. SV R&D is trying to help here publicly on regular basis if time permits for benefit of OP and also benefit of others who hit the same issue. We however cannot provide phone support when asked here. If you are a paying customer, please reach to Micro Focus support and they'll reach to us if needed and then we can jump on the call.

    Thanks for understanding.

  • ok Jakub. But Please refer my 1st Qus. Content_Type is not overriding by priority rule. If I put ignore in Type(JSONRequest). "text/plain" is reading. But if is put set. Content_Type is automatically changing.

  • Hi, I can see you are able to use the Simulation Report. Could you please navigate to Content-Type field there and click the link next to it? You will see which rule generated the value of the field. Please could you verify it's really the one you expected? I hope it's some other rule. Could you please paste a screenshot of that?

  • This code is working in local. After deployed to server
    WebRequest request = WebRequest.Create
    this line is not working

  • You need to switch off sandbox security which is switched off by default in SV Designer, but may be turned on on the Server:

    See at the very end of this page how to configure