gpt4 book ai didi

c# - 为什么我从这段代码片段中得到 'The remote server returned an error: (401) Unauthorized.'?

转载 作者:行者123 更新时间:2023-12-03 05:07:48 25 4
gpt4 key购买 nike

所以我复制粘贴了简短的代码片段

public ActionResult Run()
{
string apiKey = "ABCD-1234";
string value = "http://www.google.com"; // a url starting with http or an HTML string

using (var client = new WebClient())
{
// Build the conversion options
NameValueCollection options = new NameValueCollection();
options.Add("apikey", apiKey);
options.Add("value", value);

// Call the API convert to a PDF
MemoryStream ms = new MemoryStream(client.UploadValues("http://api.html2pdfrocket.com/pdf", options));

// Make the file a downloadable attachment - comment this out to show it directly inside
HttpContext.Response.AddHeader("content-disposition", "attachment; filename=myfilename.pdf");

// Return the file as a PDF
return new FileStreamResult(ms, "application/pdf");
}
}

来自 http://www.html2pdfrocket.com/convert-csharp-to-pdf进入我的 Web 应用程序,并收到 401 错误,堆栈跟踪如

[WebException: The remote server returned an error: (401) Unauthorized.] System.Net.WebClient.UploadValues(Uri address, String method, NameValueCollection data) +490
System.Net.WebClient.UploadValues(String address, NameValueCollection data) +35 Survey.Controllers.AnswersController.Run() +163
lambda_method(Closure , ControllerBase , Object[] ) +62
System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14

我尝试添加client = UseDefaultCredentials = true;,但无济于事。

我还可以尝试其他想法吗?

最佳答案

阅读此内容documentation

it's saying in API Authentication Section In case you don't have anaccount yet you can sign up for our 14-day free trial. To authenticateagainst our web service you're required to use your API key andusername. These can be found on your profile page and dashboard.

关于c# - 为什么我从这段代码片段中得到 'The remote server returned an error: (401) Unauthorized.'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36164362/

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