Safari/OSX Webview 更改请求类型
Safari/OSX Webview changing request type
我们正在制作我们的 Windows 应用程序的 OSX 版本,该版本严重依赖网络视图和一些 javascript API。
在Windows中,基本流程如下:
- 应用程序打开一个 webview
- 应用程序在 webview 中加载一个页面,该页面对应于我们的 javascript api
- API(写在Angular)从应用程序请求数据
- 应用returns它
- API形成一个JSON对象
- API POST 是路由服务器的 JSON 对象(在 webview 中加载时)
- 路由服务器响应对象(错误或 JSON 包含要加载的内容 URL 的对象
- API 告诉应用程序加载新的 URL
- 应用程序加载新的 URL
在 windows 这工作正常。在我们的 OSX 应用程序上,我们可以进入第 6 步。此时,出于某种我们无法弄清楚的原因,请求类型正在更改。虽然它应该是 POST,但它显示为 GET。路由服务器 returns 此时出错,因为它需要 POST(因此,POST 数据)
既然这个问题在 windows 或我们的浏览器中没有发生,是否有可能是 Safari 或 OSX 劫持了 POST 请求?也许需要使用我们错过的 on/off 选项创建 webview。我们已经四处搜索,但没有找到任何东西,所以如果有人有任何见解,我们将不胜感激。
示例 Post 请求:
{
"apptype": "Win",
"calltype": "CC",
"localTimestamp": "2014-12-10T22:37:35.499Z",
"timezone": 7,
"test": false,
"version": "1.0",
"deviceID": "Parallels-1A B0 48 1A 9F DE 43 4E 9D 99 D7 B3 10 69 4F 84",
"machineID": "19b1bde9fd7ee2efc5d15bad37101229e9d3bc11d9ac9500bffc04c0e4e638fe",
"model": "Parallels Virtual Platform",
"userID": "739e94e70db1ed4372a8744f52dd5f3d",
"country": "US",
"language": "en-US",
"contentID": "",
"prod": "DEM1",
"platformversion": "6.3.9600",
"options": {
"programArguments": {
"contentURL": "http://www.google.com"
},
"launchSource": "manual",
"visible": true
}
}
示例响应:
{
"messageID": "1",
"instructioncode": "displayContent",
"contentID": "5",
"date": "2014-12-10 15:37:36",
"sessionID": "",
"expirationdate": "2199-12-31 23:59:59",
"contentURL": "http://www.google2.com",
"options": {
"remindMinutes": "4320"
}
}
我弄明白之后就没回答过,所以这里是:
webview 是用这个创建的
- (NSURLRequest *)webView:(WebView *)sender
resource:(id)identifier
willSendRequest:(NSURLRequest *)request
redirectResponse:(NSURLResponse *)redirectResponse
fromDataSource:(WebDataSource *)dataSource
{
// Replace the request with one that ignores the cache
request = [NSURLRequest requestWithURL:[request URL]
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval:[request timeoutInterval]];
return request;
}
其目的是确保 webview 从未被缓存。它成功了!但它也劫持了每个请求并将 POST 变成 GET。解决方案只是将其注释掉并在服务器端而不是在应用程序中处理缓存内容。
- (NSURLRequest *)webView:(WebView *)sender
resource:(id)identifier
willSendRequest:(NSURLRequest *)request
redirectResponse:(NSURLResponse *)redirectResponse
fromDataSource:(WebDataSource *)dataSource
{
// Replace the request with one that ignores the cache
//request = [NSURLRequest requestWithURL:[request URL]
//cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
//timeoutInterval:[request timeoutInterval]];
return request;
}
我们正在制作我们的 Windows 应用程序的 OSX 版本,该版本严重依赖网络视图和一些 javascript API。
在Windows中,基本流程如下:
- 应用程序打开一个 webview
- 应用程序在 webview 中加载一个页面,该页面对应于我们的 javascript api
- API(写在Angular)从应用程序请求数据
- 应用returns它
- API形成一个JSON对象
- API POST 是路由服务器的 JSON 对象(在 webview 中加载时)
- 路由服务器响应对象(错误或 JSON 包含要加载的内容 URL 的对象
- API 告诉应用程序加载新的 URL
- 应用程序加载新的 URL
在 windows 这工作正常。在我们的 OSX 应用程序上,我们可以进入第 6 步。此时,出于某种我们无法弄清楚的原因,请求类型正在更改。虽然它应该是 POST,但它显示为 GET。路由服务器 returns 此时出错,因为它需要 POST(因此,POST 数据)
既然这个问题在 windows 或我们的浏览器中没有发生,是否有可能是 Safari 或 OSX 劫持了 POST 请求?也许需要使用我们错过的 on/off 选项创建 webview。我们已经四处搜索,但没有找到任何东西,所以如果有人有任何见解,我们将不胜感激。
示例 Post 请求:
{
"apptype": "Win",
"calltype": "CC",
"localTimestamp": "2014-12-10T22:37:35.499Z",
"timezone": 7,
"test": false,
"version": "1.0",
"deviceID": "Parallels-1A B0 48 1A 9F DE 43 4E 9D 99 D7 B3 10 69 4F 84",
"machineID": "19b1bde9fd7ee2efc5d15bad37101229e9d3bc11d9ac9500bffc04c0e4e638fe",
"model": "Parallels Virtual Platform",
"userID": "739e94e70db1ed4372a8744f52dd5f3d",
"country": "US",
"language": "en-US",
"contentID": "",
"prod": "DEM1",
"platformversion": "6.3.9600",
"options": {
"programArguments": {
"contentURL": "http://www.google.com"
},
"launchSource": "manual",
"visible": true
}
}
示例响应:
{
"messageID": "1",
"instructioncode": "displayContent",
"contentID": "5",
"date": "2014-12-10 15:37:36",
"sessionID": "",
"expirationdate": "2199-12-31 23:59:59",
"contentURL": "http://www.google2.com",
"options": {
"remindMinutes": "4320"
}
}
我弄明白之后就没回答过,所以这里是:
webview 是用这个创建的
- (NSURLRequest *)webView:(WebView *)sender
resource:(id)identifier
willSendRequest:(NSURLRequest *)request
redirectResponse:(NSURLResponse *)redirectResponse
fromDataSource:(WebDataSource *)dataSource
{
// Replace the request with one that ignores the cache
request = [NSURLRequest requestWithURL:[request URL]
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval:[request timeoutInterval]];
return request;
}
其目的是确保 webview 从未被缓存。它成功了!但它也劫持了每个请求并将 POST 变成 GET。解决方案只是将其注释掉并在服务器端而不是在应用程序中处理缓存内容。
- (NSURLRequest *)webView:(WebView *)sender
resource:(id)identifier
willSendRequest:(NSURLRequest *)request
redirectResponse:(NSURLResponse *)redirectResponse
fromDataSource:(WebDataSource *)dataSource
{
// Replace the request with one that ignores the cache
//request = [NSURLRequest requestWithURL:[request URL]
//cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
//timeoutInterval:[request timeoutInterval]];
return request;
}