Advertisement
Guest User

Untitled

a guest
Jul 25th, 2017
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.46 KB | None | 0 0
  1. $.ajax({
  2. type: "GET",
  3. url: "http://saskatchewan.univ-ubs.fr:8080/SASStoredProcess/do?_username=DARTIES3-2012&_password=P@ssw0rd&_program=%2FUtilisateurs%2FDARTIES3-2012%2FMon+dossier%2Fanalyse_dc&annee=2012&ind=V&_action=execute",
  4. dataType: "jsonp",
  5. }).success( function( data ) {
  6. $( 'div.ajax-field' ).html( data );
  7. });
  8.  
  9. $.ajaxPrefilter( function (options) {
  10. if (options.crossDomain && jQuery.support.cors) {
  11. var http = (window.location.protocol === 'http:' ? 'http:' : 'https:');
  12. options.url = http + '//cors-anywhere.herokuapp.com/' + options.url;
  13. //options.url = "http://cors.corsproxy.io/url=" + options.url;
  14. }
  15. });
  16.  
  17. $.get(
  18. 'http://en.wikipedia.org/wiki/Cross-origin_resource_sharing',
  19. function (response) {
  20. console.log("> ", response);
  21. $("#viewer").html(response);
  22. });
  23.  
  24. // It is good specify the charset you expect.
  25. // You can use the charset you want instead of utf-8.
  26. // See details for scriptCharset and contentType options:
  27. // http://api.jquery.com/jQuery.ajax/#jQuery-ajax-settings
  28. $.ajaxSetup({
  29. scriptCharset: "utf-8", //or "ISO-8859-1"
  30. contentType: "application/json; charset=utf-8"
  31. });
  32.  
  33. $.getJSON('http://whateverorigin.org/get?url=' +
  34. encodeURIComponent('http://google.com') + '&callback=?',
  35. function (data) {
  36. console.log("> ", data);
  37.  
  38. //If the expected response is text/plain
  39. $("#viewer").html(data.contents);
  40.  
  41. //If the expected response is JSON
  42. //var response = $.parseJSON(data.contents);
  43. });
  44.  
  45. $.get(
  46. 'http://www.corsproxy.com/' +
  47. 'en.wikipedia.org/wiki/Cross-origin_resource_sharing',
  48. function (response) {
  49. console.log("> ", response);
  50. $("#viewer").html(response);
  51. });
  52.  
  53. $.ajax({
  54. crossOrigin: true,
  55. url: url,
  56. success: function(data) {
  57. console.log(data);
  58. }
  59. });
  60.  
  61. // Create a listener.
  62. HttpListener listener = new HttpListener();
  63. // Add the prefixes.
  64. //foreach (string s in prefixes)
  65. //{
  66. // listener.Prefixes.Add(s);
  67. //}
  68. listener.Prefixes.Add("http://*:1234/"); // accept connections from everywhere,
  69. //because the printer is accessible only within the LAN (no portforwarding)
  70. listener.Start();
  71. Console.WriteLine("Listening...");
  72. // Note: The GetContext method blocks while waiting for a request.
  73. HttpListenerContext context;
  74. string urlForRequest = "";
  75.  
  76. HttpWebRequest requestForPage = null;
  77. HttpWebResponse responseForPage = null;
  78. string responseForPageAsString = "";
  79.  
  80. while (true)
  81. {
  82. context = listener.GetContext();
  83. HttpListenerRequest request = context.Request;
  84. urlForRequest = request.RawUrl.Substring(1, request.RawUrl.Length - 1); // remove the slash, which separates the portNumber from the arg sent
  85. Console.WriteLine(urlForRequest);
  86.  
  87. //Request for the html page:
  88. requestForPage = (HttpWebRequest)WebRequest.Create(urlForRequest);
  89. responseForPage = (HttpWebResponse)requestForPage.GetResponse();
  90. responseForPageAsString = new StreamReader(responseForPage.GetResponseStream()).ReadToEnd();
  91.  
  92. // Obtain a response object.
  93. HttpListenerResponse response = context.Response;
  94. // Send back the response.
  95. byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseForPageAsString);
  96. // Get a response stream and write the response to it.
  97. response.ContentLength64 = buffer.Length;
  98. response.AddHeader("Access-Control-Allow-Origin", "*"); // the magic header in action ;-D
  99. System.IO.Stream output = response.OutputStream;
  100. output.Write(buffer, 0, buffer.Length);
  101. // You must close the output stream.
  102. output.Close();
  103. //listener.Stop();
  104.  
  105. $.ajax({
  106. type: 'POST',
  107. url: 'http://LAN_IP:1234/http://google.com',
  108. success: function (data) {
  109. console.log("Success: " + data);
  110. },
  111. error: function (e) {
  112. alert("Error: " + e);
  113. console.log("Error: " + e);
  114. }
  115. });
  116.  
  117. var req = new XMLHttpRequest();
  118. req.open('GET', 'http://localhost/get_url_content.php',false);
  119. if(req.status == 200) {
  120. alert(req.responseText);
  121. }
  122.  
  123. $('.div_class').load('http://en.wikipedia.org/wiki/Cross-origin_resource_sharing #toctitle');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement