2016-03-23 11 views
7

Web API + Angularjsを使用してファイルをダウンロードしようとしていますが、うまくいきますが、Web APIのヘッダーに「content-disposition」を送信していますが、レスポンスヘッダーでアクセスできません。http.getヘッダーからコンテンツの処理を取得できませんか?

WebAPIの:

[HttpGet] 
[AllowCrossSiteJson] 
public HttpResponseMessage GetAcquisitionsTemplate() 
{ 
    var docContent = _d.FirstOrDefault(); 
    Stream stream = new MemoryStream(docContent.Content); 
    HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK); 
    string contentDisposition = string.Concat("attachment; filename=", docContent.Name.Replace(" ", String.Empty), "." + docContent.Extension); 
    result.Content = new StreamContent(stream); 
    result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");  
    result.Content.Headers.ContentDisposition = ContentDispositionHeaderValue.Parse(contentDisposition); 
    return result;    
} 

クライアント側(AngularJs):ヘッダで

$http.get(url)success(function (data, status, headers) { 
    var header= headers(); 
}) 

私は、次の値を取得していますが、私は、コンテンツ配置を取得できませんよ。私が間違っているところで私を修正してください?

enter image description here

答えて

7

私はコンテンツ処分 '(あなたができるように、サーバーのチームを尋ね、アクセス制御 - 露光 - ヘッダ、その場合には、ファイルをサーバー上でホストされている間、ローカルホストからそれをヒットしようとしていると思います')。このヘッダーを使用すると、相互参照のようなカスタムヘッダーには、クロスドメイン上でアクセスすることができます

+0

これは、レールのバックエンドで行う方法です。http://jaketrent.com/post/expose-http-headers-in-コルス/ –

関連する問題