小编GBh*_*GBh的帖子

使用c#查找和替换XML文件中的文本

我试图使用c#在xml文件中查找和替换文本.我想要的是在整个文件的url链接中更改服务器名称.

http://Server1.extranet.abc/server1webdev/rest/services/ABC/ABC_Base/MapServer
Run Code Online (Sandbox Code Playgroud)

http://Server2.extranet.abc/server1webdev/rest/services/ABC/ABC_Base/MapServer 
Run Code Online (Sandbox Code Playgroud)

我尝试使用System.xml.linq(XDocument.load(xmlpath)),但它只是将整个xml文件作为一行字符串.有没有办法可以替换文本?请注意,url不在特定节点中.它们在整个文件中是随机的.我能够通过文件的查找和替换手动执行此操作,有没有办法以编程方式执行此操作?

xml c#-4.0

6
推荐指数
1
解决办法
2万
查看次数

未经授权的 RestSharp 响应

我是基于 Web 的解决方案的新手。我正在使用 RestSharp 库访问休息 url。
我的代码如下:

var cleint = new RestClient("http://REST_URL");
cleint.Authenticator = new HttpBasicAuthenticator("username", "password");
var request = new RestRequest();
request.Method = Method.GET;
request.Resource = "0.json";

IRestResponse response = cleint.Execute(request);
if (response != null && ((response.StatusCode ==       HttpStatusCode.OK) &&
(response.ResponseStatus == ResponseStatus.Completed)))
  {
  // var arr = JsonConvert.DeserializeObject<JArray>    (response.Content);

  }
Run Code Online (Sandbox Code Playgroud)

当我手动点击它时,该 url 返回一个 json 文件。但我想使用 C# 控制台应用程序来获取 json 文件并将其保存到磁盘。当我运行上述代码时,我收到了未经授权的响应:
response.ResponseStatus= "Unauthorized"

console-application restsharp

4
推荐指数
1
解决办法
4361
查看次数

标签 统计

c#-4.0 ×1

console-application ×1

restsharp ×1

xml ×1