2016-07-06 35 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); 
相關問題