restsharp / RestSharp

Simple REST and HTTP API Client for .NET
https://restsharp.dev
Apache License 2.0
9.61k stars 2.34k forks source link

Find IRestRequest body. #880

Closed redplane closed 5 years ago

redplane commented 8 years ago

Hi everyone,

I'm using restsharp to connect to Vuforia API Service. To receive authorization key to access Vuforia Restful API, I need to read the body of POST or PUT request and calculate its md5. Here is the java code:

private String contentMD5(HttpEntityEnclosingRequestBase httpMethod) {
        ByteArrayOutputStream requestOutputStream = new ByteArrayOutputStream();
        try {
            httpMethod.getEntity().writeTo(requestOutputStream);
        } catch (IOException e) {
            System.out.println("ERROR: IOException caught when writing Content MD5 hash");
            e.printStackTrace();
        }
        return DigestUtils.md5Hex(requestOutputStream.toByteArray()).toLowerCase();
    }

But in Restsharp, I cannot find any methods/properties to help me read the body of the request.

Can anyone help me please? Thank you

DSBloom commented 7 years ago

What about the Content property?

alexeyzimarev commented 5 years ago

You can use the IRestClient.WebRequestConfigurator. The initial purpose was to give people the ability to manipulate the HttpWebRequest before we send it, but you can just get the content you need from it.