标签: response

由于mime类型不匹配,IE9脚本响应被阻止

我使用以下代码片段将谷歌融合表中的数据加载为json.

var fileref = document.createElement("script");
fileref.setAttribute("type", "text/javascript");
fileref.setAttribute("src", "http://tables.googlelabs.com/api/query?sql=select * from 588320&hdrs=false&jsonCallback=LoadTable");
Run Code Online (Sandbox Code Playgroud)

在IE8,FF,Chrome中运行良好,但现在IE9不知道如何处理回调,因为响应和mime类型不匹配.使用jsonCallback param时IE9报告以下脚本错误,因为它不喜欢mime类型.

SEC7112:来自http://tables.googlelabs.com/api/query?sql=select*的脚本来自588320&hdrs = false&jsonCallback =由于mime类型不匹配而导致LoadTable被阻止.

有一种解决方法,我不得不在本地托管src(或者我做错了什么)?

Response Headers

Content-Type text/plain; charset=UTF-8 
Content-Encoding gzip 
Transfer-Encoding chunked 
Date Fri, 13 May 2011 02:19:11 GMT 
Expires Fri, 13 May 2011 02:19:11 GMT 
Cache-Control private, max-age=0 
X-Content-Type-Options nosniff 
X-Frame-Options SAMEORIGIN 
X-XSS-Protection 1; mode=block 
Server GSE 


Request Headers

Host tables.googlelabs.com 
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1 
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 
Accept-Language en-us,en;q=0.5 
Accept-Encoding gzip, deflate 
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7 
Keep-Alive 115 …
Run Code Online (Sandbox Code Playgroud)

mime types response internet-explorer-9

12
推荐指数
1
解决办法
2万
查看次数

在C#中从WebClient读取响应头

我正在尝试创建我的第一个Windows客户端(这是我的第一个帖子),应该与"Web服务"进行通信,但是我有一些麻烦来阅读回复的响应标题.在我的响应串做我收到了很好的JSON文件回来(这是我的下一个问题),但我不能够"看到/读"的响应报头,只有身体.

下面是我正在使用的代码.

        WebClient MyClient = new WebClient();
        MyClient.Headers.Add("Content-Type", "application/json");
        MyClient.Headers.Add("User-Agent", "DIMS /0.1 +http://www.xxx.dk");
        var urlstring = "http://api.xxx.com/users/" + Username.Text;
        string response = MyClient.DownloadString(urlstring.ToString());
Run Code Online (Sandbox Code Playgroud)

c# webclient header response

12
推荐指数
3
解决办法
3万
查看次数

Angular Jasmine测试反应拦截器

我正在尝试测试我的响应拦截器,但我很难搞清楚如何模拟$ window对象.这是我的拦截器代码:

'use strict';

angular.module('Domain.handlers')

.config(function($httpProvider) {
  $httpProvider.responseInterceptors.push('UnauthorizedInterceptor');
})

.factory('UnauthorizedInterceptor', function($q, $injector, $window, ENV) {
  return function(promise) {
    var success = function(response) { return response; };
    var error   = function(response) {
      if (response.status === 401) {
        $window.location.href = ENV.account + '/oauth/authorize?client_id=' + ENV.clientId + '&redirect_uri=' + ENV.app + '/oauth/callback&response_type=token';
      }
      return $q.reject(response);
    };
    return promise.then(success, error);
  };
});
Run Code Online (Sandbox Code Playgroud)

这是我的规格:

'use strict';

describe('Domain.handlers.response', function() {
  var UnauthorizedInterceptor,
      httpProvider,
      $httpBackend,
      $http,
      token = '123456789';

  beforeEach(module('Domain.handlers', function($httpProvider) {
    httpProvider = $httpProvider;
  }));

  beforeEach(inject(function(_UnauthorizedInterceptor_, …
Run Code Online (Sandbox Code Playgroud)

testing response interceptor jasmine angularjs

12
推荐指数
1
解决办法
9907
查看次数

Laravel响应Cache-Control标头始终包含'no-cache'

出于某种原因,Laravel似乎在最后一刻操纵响应头"Cache-Control".我想使浏览器缓存成为可能.

class TestController extends Controller
{

    public function getTest()
    {
        $response = new \Illuminate\Http\Response('test', 200, array(
            'Cache-Control' => 'max-age='.(config('imagecache.lifetime')*60).', public',
            'Content-Length' => strlen('test'),
        ));

        $response->setLastModified(new \DateTime('now'));
        $response->setExpires(\Carbon\Carbon::now()->addMinutes(config('imagecache.lifetime')));

        return $response;
     }
}
Run Code Online (Sandbox Code Playgroud)

即使我使用"中间件之后"并且死掉了转发响应,我仍然会得到这个,这似乎对我来说是正确的.

Response {#625 ?
  +original: "test"
  +exception: null
  +headers: ResponseHeaderBag {#626 ?
    #computedCacheControl: array:2 [?
      "max-age" => "2592000"
      "public" => true
    ]
    #cookies: []
    #headerNames: array:5 [?]
    #headers: array:5 [?
      "cache-control" => array:1 [?
        0 => "max-age=2592000, public"
      ]
      "content-length" => array:1 [?
        0 => 4
      ]
      "date" => …
Run Code Online (Sandbox Code Playgroud)

php header response no-cache laravel

12
推荐指数
2
解决办法
2万
查看次数

如何在Strongloop上为自定义远程方法设置自定义架构

我是Strongloop的新手,我找不到有关如何自定义响应类(我构建的对象的模型架构)的信息,我不知道如何在API资源管理器上显示带有自定义数据的对象.

捕获strongloop api探险家

例如,我有一个名为score的自定义远程方法

POST /Challenges/score
Run Code Online (Sandbox Code Playgroud)

我想为参数显示data一个自定义模型模式而不是单个参数,而不是模型模式用于挑战,正文上的数据具有所有参数并向用户显示数据类型:模型模式,这可能吗?

{
  "id": "string",
  "limit": 0,
  "order": "string",
  "userId": "string"
}
Run Code Online (Sandbox Code Playgroud)

另一方面,在Response Class中,我想显示响应对象的模式.像这样的东西:

{
  "id":"string",
  "userId":"string",
  "user": {},
  "totalScore":0,
  "tags": []
}
Run Code Online (Sandbox Code Playgroud)

我看了不同的问题(这个这个),但找不到解决这个问题的东西.

更新

这是远程方法的定义

Challenge.remoteMethod('score', {
    accepts: { arg: 'data', type: 'object', http: { source: 'body' } },
    returns: {arg: 'scores', type: 'array'},
    http: {path: '/score', verb: 'post'}
});
Run Code Online (Sandbox Code Playgroud)

methods model response strongloop loopbackjs

12
推荐指数
3
解决办法
6131
查看次数

NodeJS SyntaxError:JSON 中的意外标记位于位置 0

body从Authorize.net的沙盒API的响应是:

{
  "messages": {
    "resultCode": "Error",
    "message": [
      {
        "code": "E00012",
        "text": "You have submitted a duplicate of Subscription 5777085. A duplicate subscription will not be created."
      }
    ]
  }
}
Run Code Online (Sandbox Code Playgroud)

但是当我去解析它时:

try {
   bodyObj = JSON.parse(body);
} catch (ex) {
   console.error(ex);
}
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

语法错误:JSON 中位置 0 的意外标记

和这个: console.log(response.headers['content-type']);

返回这个: application/json; charset=utf-8

我究竟做错了什么?我想将 JSON 解析为 JS 对象。

json response authorize.net node.js

12
推荐指数
1
解决办法
2万
查看次数

如何从 Spring WebClient 获取响应 json

我一直在尝试遵循最简单的教程来了解如何使用WebClient,我认为与RestTemplate.

例如,https://www.baeldung.com/spring-5-webclient#4-getting-a-response

在此处输入图片说明

所以当我尝试用https://petstore.swagger.io/v2/pet/findByStatus?status=available做同样的事情时,它应该返回一些 json,

WebClient webClient = WebClient.create();
webClient.get().uri("https://petstore.swagger.io/v2/pet/findByStatus?status=available").exchange().block();
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

我完全不知道如何从结果DefaultClientResponse对象开始。到达物理反应体不应该这么复杂,但我离题了。

如何使用我提供的代码获取响应正文?

spring response resttemplate spring-boot spring-webflux

12
推荐指数
1
解决办法
2万
查看次数

FastAPI - 如何在中间件中获取响应正文

有没有办法在中间件中获取响应内容?以下代码是从此处复制的。

@app.middleware("http")
async def add_process_time_header(request: Request, call_next):
    start_time = time.time()

    response = await call_next(request)

    process_time = time.time() - start_time
    response.headers["X-Process-Time"] = str(process_time)
    return response
Run Code Online (Sandbox Code Playgroud)

python middleware response fastapi

12
推荐指数
1
解决办法
2万
查看次数

VBScript:禁用从服务器到HTTP GET URL请求的响应缓存

我想关闭在Windows机器上的应用程序中运行的VBScript对服务器进行URL调用时使用的缓存.我用什么函数/方法/对象来做这个?

当第一次进行调用时,我的基于Linux的Apache服务器从正在运行的CGI Perl脚本返回响应.但是,后续运行的脚本似乎使用了与第一次相同的响应,因此数据正在某处缓存.我的服务器日志确认在以后的那些时间内没有调用服务器,仅在第一次.

这就是我在做的事情.我在商业应用程序中使用以下代码(不想提及此应用程序,可能与我的问题无关):


With CreateObject("MSXML2.XMLHTTP")
  .open "GET", "http://myserver/cgi-bin/nsr/nsr.cgi?aparam=1", False
  .send
  nsrresponse =.responseText
End With
Run Code Online (Sandbox Code Playgroud)

在上面的对象上是否有一个函数/方法来关闭缓存,或者我应该在创建URL之前调用一个方法/函数来关闭响应对象的缓存?

我在这里寻找解决方案:http://msdn.microsoft.com/en-us/library/ms535874(VS.85).aspx - 不是很有帮助.在这里:http://www.w3.org/TR/XMLHttpRequest/ - 非常不友好,难以阅读.

我也试图强制不使用http标头设置和html文件头元数据缓存:

服务器端Perl CGI脚本的片段,它将响应返回给调用客户端,将expiry设置为0.


    print $httpGetCGIRequest->header(
        -type    => 'text/html',
        -expires => '+0s',
        );
Run Code Online (Sandbox Code Playgroud)

响应中的Http头设置发送回客户端:


<html><head><meta http-equiv="CACHE-CONTROL" content="NO-CACHE"></head>
<body>
response message generated from server
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

上面的http标头和html文档头设置都没有用,因此我的问题.

vbscript caching response xmlhttprequest

11
推荐指数
2
解决办法
2万
查看次数

在asp.net/mvc中的控制器内的动作中为http响应添加标头

我正在将数据从服务器传输到客户端以供下载使用filestream.write.在这种情况下,发生的事情是我能够下载该文件,但它不会在我的浏览器中显示为下载."另存为"弹出窗口不会出现在"下载"部分中的"下载栏"中.从四处查看,我想我需要在响应标题中包含"something"来告诉浏览器这个响应有一个附件.我也想设置cookie.要做到这一点,这就是我在做的事情:

        [HttpContext.Current.Response.AppendHeader("Content-Disposition","attachment;filename=" & name)]
    public ActionResult Download(string name)
    {
          // some more code to get data in inputstream.

          using (FileStream fs = System.IO.File.OpenWrite(TargetFile))
            {
                byte[] buffer = new byte[SegmentSize];
                int bytesRead;
                while ((bytesRead = inputStream.Read(buffer, 0, SegmentSize)) > 0)
                {
                    fs.WriteAsync(buffer, 0, bytesRead);
                }
            }
        }
        return RedirectToAction("Index");
    }
Run Code Online (Sandbox Code Playgroud)

我收到错误:"System.web.httpcontext.current是一个属性,用作类型."

我在正确的位置更新标题吗?有没有其他方法可以做到这一点?

c# asp.net-mvc response httpcontext

11
推荐指数
2
解决办法
5万
查看次数