1

レポート(URL Access - SSRS)をダウンロードするために別のリモートマシンに存在するasp net Webページから、C#-HttpWebRequestは、Report Serverにプログラムで接続するときに400 Bad Requestを返します。

URLに直接入力すると、ブラウザから資格情報が要求され、資格情報を入力するとブラウザで自動的にレポートがダウンロードされます。 プログラムでリクエストを行うと、以下のエラーが表示されます。

C#コード:私はこの文を置いたときに、私は「ドメイン/ ABC」または「ABC @ドメイン」、 としてユーザ名を供給し、それはまた来るとき、私はHTTP 400 - 不正な要求を取得

string username="abc", password="123"; 
string url = @"http://ServerName/ReportingPath&Parameter1=123&rs:Format=PDF"; 
String encoded = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password));     
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);     
request.Headers.Add("Authorization", "Basic " + encoded); 
request.PreAuthenticate = true; 
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 11.0; Windows NT 6.0; WOW64; " + 
       "Trident/4.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; " + ".NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618; " + 
       "InfoPath.2)";     
HttpWebResponse response = (HttpWebResponse)request.GetResponse(); 

代わりにライン - >

request.Headers.Add("Authorization", "Basic " + encoded); 

私は単純にユーザー名を指定した場合、ストリッピングトンの

request.Credentials = new NetworkCredential(username,password,domain); 

彼のドメインは、username = "abc"のように、401-Unauthorizedエラーが出ます。

インターネットブラウザでURLを入力すると、エラー400または401が表示されません。私はそれが資格情報を要求する場合、レポートサーバーの

マイWebConfigのファイルはこのようなものです、「123」と「ドメイン/ ABC」、パスワードとしてユーザー名を指定する。..

<Authentication> 
<AuthenticationTypes> 
     <RSWindowsBasic/> 
</AuthenticationTypes> 
<RSWindowsExtendedProtectionLevel>Off</RSWindowsExtendedProtectionLevel> 
<RSWindowsExtendedProtectionScenario>Proxy</RSWindowsExtendedProtectionScenario> 
<EnableAuthPersistence>true</EnableAuthPersistence> 
</Authentication> 

この上の任意の助けが理解されるであろう。

答えて

0

URLを http://abc:[email protected]/ReportingPath&Parameter1=123&rs:Format=PDFと設定して認証なしで設定できますか。

これはHTTPでbasic authenticationの一部です。

+0

まだ動作していません。同じエラー「401 Unauthorized」を取得しています。ドメインにユーザー名とパスワードを渡してサーバーに渡す方法はありますか? –

+0

[ここ](http://drayblog.gotdns.com/index.php/2012/09/25/sql-2008-ssrs-web-service-access-from-net/)には実例があります。 – Ygalbel

+0

それはうまくいく..サンプルのための多くのありがとう.. –

関連する問題