C# 我发送给API的XML文件被编码,如何防止?
我正在使用一个API下载一个XML文件并读取它,这非常有效 现在我想添加一些东西并上传这个XML文件的新版本,但是它被编码了,不能用XML阅读器读取。 看起来是这样的: %3C%3Fxml%20版本%3D%221.0%22%3F%3E%0D%0A%3C 我知道我可以使用C# 我发送给API的XML文件被编码,如何防止?,c#,api,oauth,oauth-1.0a,devdefined-oauth,C#,Api,Oauth,Oauth 1.0a,Devdefined Oauth,我正在使用一个API下载一个XML文件并读取它,这非常有效 现在我想添加一些东西并上传这个XML文件的新版本,但是它被编码了,不能用XML阅读器读取。 看起来是这样的: %3C%3Fxml%20版本%3D%221.0%22%3F%3E%0D%0A%3C 我知道我可以使用HttpUtility.UrlDecode对其进行编码,但我希望有一个更好的解决方案,因为XML以这种方式存储在服务器上,这不是我想要的 下面是我用来发送请求的代码: string test = xmlFile.Insert(in
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
明白了,必须这样做:
IConsumerRequest getFileRequest = consumerSession
.Request()
.ForMethod("PUT")
.ForUri(new Uri(apiEndpoint + "/1/documents/" + documentid + "/upload"))
.WithRawContent(test, Encoding.UTF8)
.WithRawContentType("text/xml")
.SignWithToken(accessToken);
明白了,必须这样做:
IConsumerRequest getFileRequest = consumerSession
.Request()
.ForMethod("PUT")
.ForUri(new Uri(apiEndpoint + "/1/documents/" + documentid + "/upload"))
.WithRawContent(test, Encoding.UTF8)
.WithRawContentType("text/xml")
.SignWithToken(accessToken);