Search code examples
c#apioauthoauth-1.0adevdefined-oauth

XML-File i send to the API gets encoded, how to prevent that?


I am using an API to download a XML File and read it, which works perfectly.

Now i want to add something and upload a new version of this XML-File, but it gets encoded and one cant read it with an XML Reader. It looks like this:

%3C%3Fxml%20version%3D%221.0%22%3F%3E%0D%0A%3C

I know i could just encode it using HttpUtility.UrlDecode, but i would like to have a better solution, because the XML gets stored this way on the server which is not what i want.

Here the code i use to send the request:

string test = xmlFile.Insert(index, topic);
// byte[] bytes = Encoding.Default.GetBytes(test);
// test = Encoding.UTF8.GetString(bytes);

MessageBox.Show(test);

IConsumerRequest getFileRequest = consumerSession
    .Request()
    .ForMethod("PUT")
    .ForUri(new Uri(apiEndpoint + "/1/documents/" + documentid + "/upload"))
    .WithBody(test)
    .SignWithToken(accessToken);

string getFileResponse = getFileRequest.ToString();

I use the DevDefined.OAuth.Framework.


Solution

  • Got it, gotta do it like this:

    IConsumerRequest getFileRequest = consumerSession
        .Request()
        .ForMethod("PUT")
        .ForUri(new Uri(apiEndpoint + "/1/documents/" + documentid + "/upload"))
        .WithRawContent(test, Encoding.UTF8)
        .WithRawContentType("text/xml")
        .SignWithToken(accessToken);