gpt4 book ai didi

c# - 从 azure devops 服务器下载文件将错误的数据写入文件

转载 作者:行者123 更新时间:2023-12-03 16:10:42 24 4
gpt4 key购买 nike

我正在尝试使用 API 从 azure devops 服务器下载文件,但带有注销链接的 html 页面源代码被复制到文件中。我正在尝试下载一个 sql 文件。
C# 代码

 var personalaccesstoken = "wwwwwwwwwwwwwwwwwwy47b7ugkz32bubi64bw7fqdyfpa";
var url = $"https://dev.azure.com/OrgTest/ABCProject/_apis/git/repositories/e9e2f082-99999iii-dummy-869b0bcc737a/items?path=/Versiondata/Datfile/ABC.sql&includeContent=true&api-version=5.1";
var request = (HttpWebRequest)WebRequest.Create(url);
request.UserAgent = "VSTS-Get";

request.Headers.Set(HttpRequestHeader.Authorization, "Bearer " + personalaccesstoken);
request.ContentType = "application/json";
request.Method = "GET";


request.AllowAutoRedirect = true;
var response = (HttpWebResponse)request.GetResponse();
using (var responseStream = response.GetResponseStream())
{
using (var filestream = File.Create(System.IO.Path.Combine("D:\\testFolder\\", "ABC.sql")))
{
responseStream.CopyTo(filestream);
}
}
不幸的是,我在文件中的 html 内容低于
内容输出文件
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">




<html lang="en-US">
<head><title>

Azure DevOps Services | Sign In

</title><meta http-equiv="X-UA-Compatible" content="IE=11;&#32;IE=10;&#32;IE=9;&#32;IE=8" />
<link rel="SHORTCUT ICON" href="/favicon.ico"/>

<link data-bundlelength="508967" data-bundlename="commoncss" data-highcontrast="/_static/tfs/M172_20200708.14/_cssbundles/HighContrast/vss-bundle-commoncss-vbprQZmxiRGQT6OOu7QI7gB_rewyS40Ce_ulm1Fh3rQQ=" data-includedstyles="jQueryUI-Modified;Core;Splitter;PivotView" href="/_static/tfs/M172_20200708.14/_cssbundles/Default/vss-bundle-commoncss-v18eOGnLpZpVm7mtRF63HJdB9wzrq2LZpAxko9qNRfdY=" rel="stylesheet" />
<link data-bundlelength="116304" data-bundlename="viewcss" data-highcontrast="/_static/tfs/M172_20200708.14/_cssbundles/HighContrast/vss-bundle-viewcss-vv48rOLU2KepPSTALtsmN5-gXtibzGGwjVnS2QIkrRI4=" data-includedstyles="VSS.Controls" href="/_static/tfs/M172_20200708.14/_cssbundles/Default/vss-bundle-viewcss-vDH9dOETFqT44jZvM_rX-2sP7DneEj_u8KJJ1u7Bcr3I=" rel="stylesheet" />

<!--UxServices customizations -->

<link href="/_static/tfs/M172_20200708.14/_content/Authentication.css" type="text/css" rel="stylesheet" />

</head>

<body class="platform">

<script type="text/javascript"> var __vssPageContext = {"webContext":{"user":{"id":"aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa","name":"Anonymous","email":"","uniqueName":"TEAM FOUNDATION\\Anonymous"},"host":{"id":"7d0cc8e9-39e8-4313-9ff3-23ace0f8f4cf","name":"TEAM FOUNDATION","uri":"https://spsprodweu4.vssps.visualstudio.com/","relativeUri":"/","hostType":"deployment","scheme":"https","authority":"spsprodweu4.vssps.visualstudio.com"}},"moduleLoaderConfig":{"baseUrl":"/_static/tfs/M172_20200708.14/_scripts/TFS/min/","paths":{"Profile/Scripts/Resources":"en-US","VSS/Resources":"en-US","Account/Scripts/Resources":"en-US","UserManagement/Scripts/Resources":"en-US","Authentication/Scripts/Resources":"en-US"},"map":{},"contributionPaths":{"VSS":{"value":"/_static/tfs/M172_20200708.14/_scripts/TFS/min/VSS","pathType":"default"},"VSS/Resources":{"value":"en-US","pathType":"resource"},"q":{"value":"/_static/tfs/M172_20200708.14/_scripts/TFS/min/q","pathType":"default"},"knockout":{"value":"/_static/tfs/M172_20200708.14/_scripts/TFS/min/knockout","pathType":"default"},"mousetrap":{"value":"/_static/tfs/M172_20200708.14/_scripts/TFS/min/mousetrap","pathType":"default"},"mustache":{"value":"/_static/tfs/M172_20200708.14/_scripts/TFS/min/mustache","pathType":"default"},"react":{"value":"/_static/tfs/M172_20200708.14/_scripts/TFS/min/react.15.3","pathType":"default"},"react-dom":{"value":"/_static/tfs/M172_20200708.14/_scripts/TFS/min/react-dom.15.3","pathType":"default"},"react-transition-group":{"value":"/_static/tfs/M172_20200708.14/_scripts/TFS/min/react-transition-group.15.3","pathType":"default"},"jQueryUI":{"value":"/_static/tfs/M172_20200708.14/_scripts/TFS/min/jQueryUI","pathType":"default"},"jquery":{"value":"/_static/tfs/M172_20200708.14/_scripts/TFS/min/jquery","pathType":"default"},"OfficeFabric":{"value":"/_static/tfs/M172_20200708.14/_scripts/TFS/min/OfficeFabric","pathType":"default"},"tslib":{"value":"/_static/tfs/M172_20200708.14/_scripts/TFS/min/tslib","pathType":"default"},"@uifabric":{"value":"/_static/tfs/M172_20200708.14/_scripts/TFS/min/@uifabric","pathType":"default"},"VSSUI":{"value":"/_static/tfs/M172_20200708.14/_scripts/TFS/min/VSSUI","pathType":"default"}},"shim":{"jquery":{"deps":[],"exports":"jQuery"}},"waitSeconds":30},"coreReferences":{"stylesheets":[{"url":"/_static/tfs/M172_20200708.14/_cssbundles/Default/vss-bundle-ext-core-css-vQ8Us1s7UaJe7EYaHu4abPhUIoy4VkQeq0UCGlmbyyiE=","highContrastUrl":null,"isCoreStylesheet":true}],"scripts":[{"identifier":"JQuery","url":"/_static/3rdParty/_scripts/jquery-2.2.4.min.js","fallbackUrl":null,"fallbackCondition":null,"isCoreModule":true},{"identifier":"JQueryXDomain","url":"/_static/3rdParty/_scripts/jquery.xdomainrequest.min.js","fallbackUrl":null,"fallbackCondition":null,"isCoreModule":true},{"identifier":"Promise","url":"/_static/tfs/M172_20200708.14/_scripts/TFS/min/promise.js","fallbackUrl":null,"fallbackCondition":null,"isCoreModule":true},{"identifier":"GlobalScripts","url":"/_static/tfs/M172_20200708.14/_scripts/TFS/min/global-scripts.js","fallbackUrl":null,"fallbackCondition":null,"isCoreModule":true},{"identifier":"LoaderFixes","url":"/_static/tfs/M172_20200708.14/_scripts/TFS/pre-loader-shim.min.js","fallbackUrl":null,"fallbackCondition":null,"isCoreModule":false},{"identifier":"AMDLoader","url":"/_static/3rdParty/_scripts/require.min.js","fallbackUrl":null,"fallbackCondition":null,"isCoreModule":true},{"identifier":"LoaderFixes","url":"/_static/tfs/M172_20200708.14/_scripts/TFS/post-loader-shim.min.js","fallbackUrl":null,"fallbackCondition":null,"isCoreModule":false}],"coreScriptsBundle":{"identifier":"CoreBundle","url":"/_public/_Bundling/Content?bundle=vss-bundle-basejs-v9GpWWBnsWqhM23ijhK2HfAqLowTXGUqZLDRsBCZbkfY=","fallbackUrl":null,"fallbackCondition":null,"isCoreModule":true},"extensionCoreReferences":{"identifier":"CoreBundle","url":"/_public/_Bundling/Content?bundle=vss-bundle-ext-core-vXmFrbZVv9in776dlqjrJLCGMci5PQIF14Ug3E2n2Ku0=","fallbackUrl":null,"fallbackCondition":null,"isCoreModule":true}},"webAccessConfiguration":{"isHosted":true,"paths":{"rootPath":"/","staticContentRootPath":"/","staticContentVersion":"M172_20200708.14","resourcesPath":"/_static/tfs/M172_20200708.14/_content/","staticRootTfs":"/_static/tfs/M172_20200708.14/","cdnFallbackStaticRootTfs":"/_static/tfs/M172_20200708.14/","staticRoot3rdParty":"/_static/3rdParty/"},"api":{"webApiVersion":"1","areaPrefix":"_","controllerPrefix":""},"mailSettings":{"enabled":false},"registryItems":{}},"microsoftAjaxConfig":{"cultureInfo":{"name":"en-US","numberFormat":{"CurrencyDecimalDigits":2,"CurrencyDecimalSeparator":".","IsReadOnly":true,"CurrencyGroupSizes":[3],"NumberGroupSizes":[3],"PercentGroupSizes":[3],"CurrencyGroupSeparator":",","CurrencySymbol":"$","NaNSymbol":"NaN","CurrencyNegativePattern":0,"NumberNegativePattern":1,"PercentPositivePattern":1,"PercentNegativePattern":1,"NegativeInfinitySymbol":"-∞","NegativeSign":"-","NumberDecimalDigits":2,"NumberDecimalSeparator":".","NumberGroupSeparator":",","CurrencyPositivePattern":0,"PositiveInfinitySymbol":"∞","PositiveSign":"+","PercentDecimalDigits":2,"PercentDecimalSeparator":".","PercentGroupSeparator":",","PercentSymbol":"%","PerMilleSymbol":"‰","NativeDigits":["0","1","2","3","4","5","6","7","8","9"],"DigitSubstitution":1},"dateTimeFormat":{"AMDesignator":"AM","Calendar":{"MinSupportedDateTime":"0001-01-01T00:00:00","MaxSupportedDateTime":"9999-12-31T23:59:59.9999999","AlgorithmType":1,"CalendarType":1,"Eras":[1],"TwoDigitYearMax":2029,"IsReadOnly":true},"DateSeparator":"/","FirstDayOfWeek":0,"CalendarWeekRule":0,"FullDateTimePattern":"dddd, MMMM d, yyyy h:mm:ss tt","LongDatePattern":"dddd, MMMM d, yyyy","LongTimePattern":"h:mm:ss tt","MonthDayPattern":"MMMM d","PMDesignator":"PM","RFC1123Pattern":"ddd, dd MMM yyyy HH':'mm':'ss 'GMT'","ShortDatePattern":"M/d/yyyy","ShortTimePattern":"h:mm tt","SortableDateTimePattern":"yyyy'-'MM'-'dd'T'HH':'mm':'ss","TimeSeparator":":","UniversalSortableDateTimePattern":"yyyy'-'MM'-'dd HH':'mm':'ss'Z'","YearMonthPattern":"MMMM yyyy","AbbreviatedDayNames":["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],"ShortestDayNames":["Su","Mo","Tu","We","Th","Fr","Sa"],"DayNames":["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],"AbbreviatedMonthNames":["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec",""],"MonthNames":["January","February","March","April","May","June","July","August","September","October","November","December",""],"IsReadOnly":true,"NativeCalendarName":"Gregorian Calendar","AbbreviatedMonthGenitiveNames":["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec",""],"MonthGenitiveNames":["January","February","March","April","May","June","July","August","September","October","November","December",""]},"numberShortForm":{"QuantitySymbols":["K","M","B"],"NumberGroupSize":1000,"ThousandSymbol":"K"},"eras":null}},"timeZonesConfiguration":{},"featureAvailability":{"featureStates":{"VisualStudio.Services.Contribution.EnableOnPremUnsecureBrowsers":false,"VisualStudio.Service.WebPlatform.ClientErrorReporting":false,"Microsoft.VisualStudio.Services.Gallery.Client.UseCdnAssetUri":false,"VisualStudio.Services.WebAccess.SubresourceIntegrity":false,"VisualStudio.Services.IdentityPicker.ReactProfileCard":true}},"appInsightsConfiguration":{"enabled":false,"instrumentationKey":"00000000-0000-0000-0000-000000000000","insightsScriptUrl":null},"diagnostics":{"sessionId":"f6a1e2ac-a812-49e0-9d52-d7ee7f8143d0","activityId":"f6a1e2ac-a812-49e0-9d52-d7ee7f8143d0","bundlingEnabled":true,"webPlatformVersion":"M172","serviceVersion":"Dev18.M172.1 (build: AzureDevOps_M172_20200708.14)"},"navigation":{"topMostLevel":"deployment","area":"","currentController":"Signin","currentAction":"Index","routeId":"LegacyWebAccessRoute","routeValues":{"controller":"Signin","action":"Index"}},"globalization":{"explicitTheme":"","theme":"Default","culture":"en-US","timezoneOffset":0,"timeZoneId":"UTC"},"serviceInstanceId":"951917ac-a960-4999-8464-e3f0aa25b381","hubsContext":{},"serviceLocations":{"locations":{"951917ac-a960-4999-8464-e3f0aa25b381":{"Application":"https://spsprodweu4.vssps.visualstudio.com/","Deployment":"https://spsprodweu4.vssps.visualstudio.com/"}}}};</script><script type="text/javascript"> var __cultureInfo = __vssPageContext.microsoftAjaxConfig.cultureInfo;</script>
<script type="text/javascript">if (window.performance && window.performance.mark) { window.performance.mark('startLoadBundleOuter-basejs'); }</script>
<script data-bundlelength="125076" data-bundlename="basejs" src="/_public/_Bundling/Content?bundle=vss-bundle-basejs-v9GpWWBnsWqhM23ijhK2HfAqLowTXGUqZLDRsBCZbkfY=" type="text/javascript"></script>
<script type="text/javascript">if (window.performance && window.performance.mark) { window.performance.mark('endLoadBundleOuter-basejs'); }</script>


<script type="text/javascript"> require.config(__vssPageContext.moduleLoaderConfig);</script>

<input name="__RequestVerificationToken" type="hidden" value="NczcE2VqtZurcha-i70MYWJmzvklYWzgZmMOD4_U9KGkpElkwsliaVLxrc5SUWZXGi0kzpaOtqckBS6JZEDleh7ctQA1" /><input name="__RequestVerificationToken2" type="hidden" value="__RequestVerificationToken209a26724-ac5a-4587-887f-60eb94fca407" />






<div class="account signin main-container hide">


<div class="page-content">
<div class="header-section" role="banner">


<link rel="stylesheet" type="text/css" href="/_static/tfs/M172_20200708.14/_content/Combined.css">
<div id="ux-header" class="FF ltr vsIntegrate" xmlns="http://www.w3.org/1999/xhtml">
<span id="isMobile"></span>
<div class="upperBand">
<div class="upperBandContent">
<div class="left"></div>
<div class="right">
<div class="profileImage"></div>

<div id="signIn">
<a class=":SignedOutProfileElement: createProfileLink" href="/go/profile" title="Anonymous">Anonymous</a>
<a class="scarabLink" href="/_signout">Sign out</a>
</div>
</div>
<div class="clear-both"></div>
</div>
</div>
</div>
</div>
<div class="content-section" role="main">


<div class="signin-main-content">
<noscript>
<span class="error">Microsoft Internet Explorer&#39;s Enhanced Security Configuration is currently enabled on your environment. This enhanced level of security prevents our web integration experiences from displaying or performing correctly. To continue with your operation please disable this configuration or contact your administrator.</span>
</noscript>
<div class="provider-control">
<script class="options" defer="defer" type="application/json">{"providerOptions":{"force":false,"orgIdAuthUrl":"https://login.microsoftonline.com/c627bf07-e774-48cd-9e33-eeeed30d747b/oauth2/authorize?client_id=499b84ac-1321-427f-aa17-267ca6975798\u0026site_id=501454\u0026response_mode=form_post\u0026response_type=code+id_token\u0026redirect_uri=https%3A%2F%2Fspsprodweu4.vssps.visualstudio.com%2F_signedin\u0026nonce=15b49048-8f5c-43a8-8e2d-77067ccdbc15\u0026state=realm%3Ddev.azure.com%26reply_to%3Dhttps%253A%252F%252Fdev.azure.com%252FOrgnatinTest%252FAIProject%252F_apis%252Fgit%252Frepositories%252Fe9e2f082-6f6d-4cfd-a7af-869b0bcc737a%252Fitems%253Fpath%253D%25252FV4.1.0.0%25252FDB%25252FDWH%25252FDWH%25252FDWH%25252FAMF.sql%2526includeContent%253Dtrue%2526api-version%253D5.1%26ht%3D2%26hid%3D750bf9a1-4ded-4c22-89dd-a2740fccd529%26nonce%3D15b49048-8f5c-43a8-8e2d-77067ccdbc15\u0026resource=https%3A%2F%2Fmanagement.core.windows.net%2F\u0026cid=15b49048-8f5c-43a8-8e2d-77067ccdbc15\u0026wsucxt=1","user":null,"signInContext":"eyJodCI6MiwiaGlkIjoiMTY0NmI1NzMtNjNhOS00MzYyLWE0MjItYzA0MzEyYTI4MjU3IiwicXMiOnsicmVhbG0iOiJkZXYuYXp1cmUuY29tIiwicmVwbHlfdG8iOiJodHRwczovL2Rldi5henVyZS5jb20vUGF0aFNvbHV0aW9uc1Rlc3QvQUlQcm9qZWN0L19hcGlzL2dpdC9yZXBvc2l0b3JpZXMvZTllMmYwODItNmY2ZC00Y2ZkLWE3YWYtODY5YjBiY2M3MzdhL2l0ZW1zP3BhdGg9JTJGVjQuMS4wLjAlMkZEQiUyRkRXSCUyRkRXSCUyRkRXSCUyRkFNRi5zcWwmaW5jbHVkZUNvbnRlbnQ9dHJ1ZSZhcGktdmVyc2lvbj01LjEiLCJodCI6IjIiLCJoaWQiOiI3NTBiZjlhMS00ZGVkLTRjMjItODlkZC1hMjc0MGZjY2Q1MjkiLCJub25jZSI6IjE1YjQ5MDQ4LThmNWMtNDNhOC04ZTJkLTc3MDY3Y2NkYmMxNSJ9LCJyciI6IiIsInZoIjoiIiwiY3YiOiIiLCJjcyI6IiJ90"}}</script>
</div>
</div>


</div>


</div>





<script type="text/javascript">if (window.performance && window.performance.mark) { window.performance.mark('startLoadBundleOuter-common'); }</script>
<script data-bundlelength="205378" data-bundlename="common" data-includedscripts="VSS/Bundling" src="/_public/_Bundling/Content?bundle=vss-bundle-common-v_Ss9wqVqy_aJagjjTroIfzbnjzMUeKzN0KlnLkpPbLw=" type="text/javascript"></script>
<script type="text/javascript">if (window.performance && window.performance.mark) { window.performance.mark('endLoadBundleOuter-common'); }</script>
<script type="text/javascript">if (window.performance && window.performance.mark) { window.performance.mark('startLoadBundleOuter-view'); }</script>
<script data-bundlelength="157426" data-bundlename="view" data-includedscripts="Authentication/Scripts/SPS.Authentication.Controls;Authentication/Scripts/SPS.Authentication" src="/_public/_Bundling/Content?bundle=vss-bundle-view-vip8jjFGoJo8AL2ac18TvWQ8inaN47zLqW97-Gn61kAs=" type="text/javascript"></script>
<script type="text/javascript">if (window.performance && window.performance.mark) { window.performance.mark('endLoadBundleOuter-view'); }</script>

<script type="text/javascript"> if (window.performance && window.performance.mark) { window.performance.mark('requireStart'); }
require(["Authentication/Scripts/SPS.Authentication.Controls","Authentication/Scripts/SPS.Authentication"], function(){ if (window.performance && window.performance.mark) { window.performance.mark('requireEnd'); } window.requiredModulesLoaded=true; });
</script>

</body>
</html>
如何获得确切的 output.credentials 和 token 是相同的。我尝试从下行链接下载。我面临同样的问题。任何解决方案?我们是否应该为 azure devops 服务器中开发的应用程序添加授权。

最佳答案

最后我找到了这个问题的解决方案。这里我们尝试使用个人访问 token (PAT)。为了使用 PAT 进行身份验证,我们必须使用授权为 "Basic"而不是 "Bearer" .更多的是,我们必须使用 ,而不是将 PAT 单独添加到请求 header 中。用户名和 PAT 的组合 . 说 base-64-encoded-string of username:PAT。
所需代码更改

var personalaccesstoken = "wwwwwwwwwwwwwwwwwwy47b7ugkz32bubi64bw7fqdyfpa";
var base64Creds = Convert.ToBase64String(Encoding.ASCII.GetBytes("SPabbbal@ABCTech.com:"+ personalaccesstoken));
request.Headers.Set(HttpRequestHeader.Authorization, "Basic " + base64Creds);
谢谢你的支持。

关于c# - 从 azure devops 服务器下载文件将错误的数据写入文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63407273/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com