Search code examples
blueprism

Blue Prism web api service - Cannot send a content-body with this verb-type


I'm having some trouble getting a GET Action with body to work in BluePrism (using web api service).

It seems that when I try to include an Action that sends a GET with body when I reach that stage this error gets thrown:

Internal : Unexpected error Cannot send a content-body with this verb-type.

What I've tried:

  • Using a different verb-type / passing parameters in the query instead of the body, unfortunately i don't have control over the endpoint i'm trying to reach so this didnt work as it only accepts a GET containing data in the body
  • Using BluePrism HTTP Utility to send the call, this has the same problem as the Web API Service
  • Compiling the body via code instead of using a template

I haven't been able to find anyone that made it work in BluePrism and there doesn't seem to be much documentation on this issue in BluePrism so any help would be appreciated.

Thanks!


Solution

  • I managed to get it working using a code block containing C# code and using Reflection, here is a my GET method:

    public string GetWithBodyAndAuth(string uri, string data, string token, out int statusCode)
    {
        var request = (HttpWebRequest)WebRequest.Create(uri);
        
        
        request.Headers.Add("Authorization", "Basic " + token);
        request.ContentType = "application/json; charset=utf-8";
        request.Method = "GET";
        request.Accept = "application/json";
    
        var type = request.GetType();
        var currentMethod = type.GetProperty("CurrentMethod", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(request);
    
        var methodType = currentMethod.GetType();
        methodType.GetField("ContentBodyNotAllowed", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(currentMethod, false);
    
        using (var streamWriter = new StreamWriter(request.GetRequestStream()))
        {
            streamWriter.Write(data);
        }
    
        var response = (HttpWebResponse)request.GetResponse();
        StreamReader reader = new StreamReader(response.GetResponseStream());
        statusCode = ((int)response.StatusCode);
        return reader.ReadToEnd();
    }
    

    It's a bit of a hack and can't say if it'll be supported in the future, but for BluePrism 6.9 this allows you to send GET requests containing a body.

    It has the advantage of not requiring any external DLLs, this is the import list:

    Import List