我试图将POST请求发送到API,该API需要请求正文中的XML并使用XML数据进行响应。API位于另一个域中,因此必须使用CORS。IE11发送了一个成功的CORS预飞。下面是一个简化的测试用例,它在Windows 7上的Internet 11上发生了以下错误:
SCRIPT7002: XMLHttpRequest: Network Error 0x800c0007, No data is available for the requested resource.
var body = '<?xml version="1.0" encoding="UTF-8"?> '
+ '<Trias version="1.1" xmlns="http://www.vdv.de/trias" xmlns:siri="http://www.siri.org.uk/siri" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> '
+ ' <ServiceRequest> '
+ ' <siri:RequestTimestamp>2016-06-27T13:34:00</siri:RequestTimestamp> '
+ ' <siri:RequestorRef>EPSa</siri:RequestorRef> '
+ ' <RequestPayload> '
+ ' <StopEventRequest> '
+ ' <Location> '
+ ' <LocationRef> '
+ ' <StopPointRef>8502113</StopPointRef> '
+ ' </LocationRef> '
+ ' <DepArrTime>2017-01-03T10:22:00</DepArrTime>'
+ ' </Location> '
+ ' <Params> '
+ ' <NumberOfResults>1</NumberOfResults> '
+ ' <StopEventType>departure</StopEventType> '
+ ' <IncludePreviousCalls>true</IncludePreviousCalls> '
+ ' <IncludeOnwardCalls>true</IncludeOnwardCalls> '
+ ' <IncludeRealtimeData>true</IncludeRealtimeData> '
+ ' </Params> '
+ ' </StopEventRequest> '
+ ' </RequestPayload> '
+ ' </ServiceRequest> '
+ '</Trias> ';
$(document).ready(function() {
$('button').click(function() {
$.ajax('https://odpch-api.begasoft.ch/trias-stackoverflow', {
method: 'POST',
headers: {
'Content-Type': 'text/xml',
'Authorization': '57c5dadd5e6307000100005e4365c41fa4d946a44ecbd19508fbef64'
},
data: body,
dataType: 'text'
}).done(function(data) {
$('#response').text(data);
});
});
});<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
</head>
<body>
<button>Ajax</button>
<div id="response"></div>
</body>
</html>
编辑:从代码段运行它会给出另一个错误,下面是一个完整的示例:http://pastebin.com/yTL7mrYF
试飞前请求和post请求本身在dev工具中可见。对于POST请求,只有响应头是可见的,但是响应主体说“没有要查看的数据”。
我在Fiddler中看到响应是从服务器发送回来的,但是无法显示它。
这个服务是一个API管理软件Tyk的背后。
这显然适用于Firefox和Chrome。
发布于 2017-01-16 16:59:55
问题是压缩响应(平减)。当我移除接受编码请求头时,响应不会被压缩,它在Internet中工作。
https://stackoverflow.com/questions/41638095
复制相似问题