如何从 C# 客户端发送补丁请求? [英] How do you send a patch request from a c# client?

查看:33
本文介绍了如何从 C# 客户端发送补丁请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个执行此操作的 powershell 脚本:

I have a powershell script that does this :

    $uri = "$($tfsUri)/$($teamproject)/_apis/build/builds/$($buildID)?api-version=2.0"
    $data = @{keepForever = $keepForever} | ConvertTo-Json
    $response = $webclient.UploadString($uri,"PATCH", $data) 

我正在尝试使用 Web 客户端在 C# 中重写它.

I'm trying to rewrite this in C#, using a Webclient.

WebClient client = new WebClient();
client.Encoding = System.Text.Encoding.UTF8;
string reply = client.UploadString(url, "keepForever = true");
Console.WriteLine(reply);

但我得到:远程服务器返回错误:(401) 未经授权.

But I get : The remote server returned an error: (401) Unauthorized.

这是 TFS 2015 VNext,如果有帮助的话.

This is TFS 2015 VNext, if that helps.

推荐答案

您在调用 上传字符串.

string reply = client.UploadString(url, "keepForever = true");

应该是:

string reply = client.UploadString(url, "PATCH", "keepForever = true");

401 是未经授权的,因此还要查看您的 Powershell 之前是否有您登录或加入会话的步骤,您需要在 C# 中复制该步骤.

A 401 is unauthorised, so also see if there is a step before in your Powershell where you are logging in or joining a session, you would need to replicate that in your C#.

这篇关于如何从 C# 客户端发送补丁请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆