Created
December 21, 2016 16:51
-
-
Save micahnyc/0b426bdbb3b4a95bb3792b439e2897e3 to your computer and use it in GitHub Desktop.
webview js xhr post
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var startScript = "var http = new XMLHttpRequest();" | |
startScript += "var url = 'http://192.168.1.43:8080/liveControl';var params = 'action=LivePreviewCtl&control=true';http.open('POST', url, true);" | |
startScript += "http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');" | |
startScript += "http.onreadystatechange = function() {" | |
startScript += "http.onreadystatechange = function() {" | |
startScript += "if(http.readyState == 4 && http.status == 204) {" | |
startScript += "console.log(http.responseText);" | |
startScript += "} else { console.log('error with preview', http.status); }" | |
startScript += "http.send(params);" | |
liveStreamWebView.evaluateJavaScript(startScript) { (reult, error) in | |
print("started preview") | |
DispatchQueue.main.asyncAfter(deadline: .now() + 0.25, execute: { | |
let request = URLRequest(url: LiveRestApi.livePreviewUrl) | |
self.liveStreamWebView.load(request) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment