2016-07-06 40 views
1

我正在使用API​​下载XML文件并阅读它,它完美地工作。我发送到API的XML文件被编码,如何防止?

现在我想添加一些东西并上传这个XML文件的新版本,但是它被编码,并且一个不能用XML读取器读取它。 它看起来像这样:

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

我知道我可以把它用HttpUtility.UrlDecode只是编码,但我想有一个更好的解决方案,因为XML以这种方式存储在服务器上,这不是我想要的。

下面的代码我用来发送请求:

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(); 

我用的是DevDefined.OAuth.Framework

回答

0

得到它,你必须这样做是这样的:

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