2016-03-22 17 views
0

Yani benim web uygulaması içine http://www.html2pdfrocket.com/convert-csharp-to-pdf gelen kısa kod parçacığınıNeden "Uzak sunucu bir hata verdi: (401) Yetkisiz." bu kod snippet'inden mi?

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"); 
    } 
} 

yapıştırılan-kopyalayıp

[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

Hiçbir için, client = UseDefaultCredentials = true; ekleyerek çalıştı gibi bir yığın izleme ile 401 hatası alıyorum boşuna.

Denediğim başka fikirler var mı?

+0

okumak? –

+1

bu dokümanı okuyun https://html2pdfwebservice.com/documentation API Kimlik Doğrulama Bölümü'nde diyor. Henüz bir hesabınız yoksa, 14 günlük ücretsiz deneme sürümümüze kayıt olabilirsiniz. Web servisimize karşı kimlik doğrulaması yapmak için API anahtarınızı ve kullanıcı adınızı kullanmanız gerekir. Bunlar profil sayfanızda ve gösterge panosunda bulunabilir. – rashfmnb

+0

Oh, paraya mı mal oluyor? Boşver. –

cevap

3

Eğer vekil tanımlayan denediniz bu documentation

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

+0

html2pdfwebservice.com, html2pdfrocket ile aynı değildir. Biliyorum çünkü HTML2PDF Web Service :-) sahibiyim. – Htbaa

İlgili konular