だから私は自分のWebアプリケーションにhttp://www.html2pdfrocket.com/convert-csharp-to-pdfから簡単なコードスニペットなぜ私は 'リモートサーバがエラーを返しました:(401)Unauthorized。'このコードスニペットから?
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");
}
}
を-貼り付けコピーして、私はnoに、client = UseDefaultCredentials = true;
に追加しようとした
[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
のようなスタックトレースと401エラーを取得しています利用可能。
私が試すことができる他のアイデアは?
を読みますか? –
この文書をお読みくださいAPI認証セクションでhttps://html2pdfwebservice.com/documentationと言っています。まだアカウントをお持ちでない場合は、14日間無料トライアルにサインアップできます。 Googleのウェブサービスを認証するには、APIキーとユーザー名を使用する必要があります。これらはあなたのプロフィールページとダッシュボードにあります。 – rashfmnb
ああ、お金がかかりますか?気にしないで。 –