我们制作的Windows应用程序的OSX版本严重依赖于网页浏览和一些JavaScript API。
在Windows中,基本流程如下:
在Windows上,这很好用。在我们的OSX应用程序中,我们可以进入第6步。此时,由于某种原因我们无法弄清楚,请求类型正在改变。虽然它应该是一个POST,而是显示为GET。路由服务器此时返回错误,因为它期望POST(因此,POST数据)
由于这个问题在Windows或我们的浏览器中都没有发生,Safari或OSX是否有可能劫持POST请求?也许webview需要创建一个我们错过的打开/关闭选项。我们一直在寻找,但是没有找到任何东西,所以如果有人有任何见解,我们将非常感激。
示例发布请求:
{
"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"
}
}
答案 0 :(得分:1)
在我弄清楚之后,我从未回答过这个问题,所以这就是:
使用此
创建了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;
}