Search Results

Search found 540 results on 22 pages for 'indexof'.

Page 1/22 | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Array indexOf implementation for Internet Explorer

    - by Daemon
    There are plenty of solutions on how to get the indexOf implementation into the Array prototype so that it works under Internet Explorer, however I've stumbled upon an issue that doesn't seem to be addressed anywhere I've looked so far. Using the pretty well agreed upon implementation at MDC, I have the following code that's being problematic now: // indexOf support for IE (from MDC) if (!Array.prototype.indexOf) { Array.prototype.indexOf = function(elt /*, from*/) { var len = this.length >>> 0; var from = Number(arguments[1]) || 0; from = (from < 0) ? Math.ceil(from) : Math.floor(from); if (from < 0) from += len; for (; from < len; from++) { if (from in this && this[from] === elt) return from; } return -1; }; } var i = [1,2,3,4]; for (j in i) { alert(i[j]); } I am expecting to receive 4 alerts, each one containing one of the elements of the array. In Firefox and Chrome, that's exactly what I see, however in IE8 I get an additional alert containing the indexOf function code. What can be done to avoid this?

    Read the article

  • Array indexOf implentation for Internet Explorer

    - by Daemon
    There are plenty of solutions on how to get the indexOf implementation into the Array prototype so that it works under Internet Explorer, however I've stumbled upon an issue that doesn't seem to be addressed anywhere I've looked so far. Using the pretty well agreed upon implementation at MDC, I have the following code that's being problematic now: // indexOf support for IE (from MDC) if (!Array.prototype.indexOf) { Array.prototype.indexOf = function(elt /*, from*/) { var len = this.length >>> 0; var from = Number(arguments[1]) || 0; from = (from < 0) ? Math.ceil(from) : Math.floor(from); if (from < 0) from += len; for (; from < len; from++) { if (from in this && this[from] === elt) return from; } return -1; }; } var i = [1,2,3,4]; for (j in i) { alert(i[j]); } I am expecting to receive 4 alerts, each one containing one of the elements of the array. In Firefox and Chrome, that's exactly what I see, however in IE8 I get an additional alert containing the indexOf function code. What can be done to avoid this?

    Read the article

  • IndexOf method returns 0 when it should had return -1 in C# / Java

    - by jcgarciam
    A friend of mine came to me with this strange behavior which i can't explain, any insight view would be appreciated. Im running VS 2005 (C# 2.0), the following code show the behavior int rr = "test".IndexOf(""); Console.WriteLine(rr.ToString()); the above code, print "0" which clearly show it should have return -1 This also happen in Java where the following Class show the behavior: public class Test{ public static void main(String[] args){ System.out.println("Result->"+("test".indexOf(""))); } } Im running Java 1.6.0_17

    Read the article

  • ArrayList of my objects, indexOf problem

    - by majtits
    Hello! I have problem with Java's ArrayList. I've created an Object, that contains two atributes, x and y. Now I've loaded some object in my ArrayList. Problem is that I don't know how to find index of some object with x atribute I'm searching. Is there any way to do this?

    Read the article

  • How can I use IndexOf to pick a specific Character when there are more than one of them?

    - by JimDel
    How can I use IndexOf with SubString to pick a specific Character when there are more than one of them? Here's my issue. I want to take the path "C:\Users\Jim\AppData\Local\Temp\" and remove the "Temp\" part. Leaving just "C:\Users\Jim\AppData\Local\" I have solved my problem with the code below but this assumes that the "Temp" folder is actually called "Temp". Is there a better way? Thanks if (Path.GetTempPath() != null) // Is it there?{ tempDir = Path.GetTempPath(); //Make a string out of it. int iLastPos = tempDir.LastIndexOf(@"\"); if (Directory.Exists(tempDir) && iLastPos > tempDir.IndexOf(@"\")) { // Take the position of the last "/" and subtract 4. // 4 is the lenghth of the word "temp". tempDir = tempDir.Substring(0, iLastPos - 4); }}

    Read the article

  • Java String.indexOf and empty Strings

    - by tmeisenh
    I'm curious why the String.indexOf is returning a 0 (instead of -1) when asking for the index of an empty string within a string. The Javadocs only say this method returns the index in this String of the specified string, -1 if the string isn't found. System.out.println("FOO".indexOf("")); // outputs 0 wtf!!! System.out.println("FOO".indexOf("bar")); // outputs -1 as expected System.out.println("FOO".indexOf("F")); // outputs 0 as expected System.out.println("".indexOf("")); // outputs 0 as expected, I think

    Read the article

  • jquery attribute indexOf

    - by Victor
    When I am getting at an attribute onclick of custom(Reporting Services) checkbox it gives me correct result. However when I am trying to use indexOf on that result it says "Object doesn't support this property or method", i.e. this is fine, gives me a long string $('input[id*=CustomCheckBox]').click(function() { alert( $(this).attr("onclick") ); }); But this gives an error(object doesn't support this property or method): $('input[id*=CustomCheckBox]').click(function() { if ($(this).attr("onclick").indexOf("SomeString") > -1 ) { //do some processing here } } What would I need to modify so that indexOf is working properly?

    Read the article

  • Why is Java String indexOf failing?

    - by Binaryrespawn
    Hi all, this must be quite simple but I am having great difficulty. You see I am trying to find a string within another string as follows. e = input.indexOf("-->"); s = input.indexOf("<!--"); input = input.replace(input.substring(s, e + 3), " "); The integers e and s are returning -1 in that it was not found and this is causing the replace method to fail. The test string I am using is "Chartered Certified<!--lol--> Accountants (ACCA)". I tried to creat a new string object and pass in the string as an argument as follows e=input.indexOf(new String("<!--")); This yielded the same result. Any ideas ?

    Read the article

  • C# collection/string .Contains vs collection/string.IndexOf

    - by Daniel
    Is there a reason to use .Contains on a string/list instead of .IndexOf? Most code that I would write using .Contains would shortly after need the index of the item and therefore would have to do both statements. But why not both in one? if ((index = blah.IndexOf(something) = 0) // i know that Contains is true and i also have the index

    Read the article

  • Javascript indexOf() always returns -1

    - by Thomas
    I try to retrieve the index of en element in an array. This works perfectly var onCreate = function (event) { console.assert(markers[markerId] === undefined); var markerId = event.markerId; markers[markerId] = {}; var marker = markers[markerId]; // create the container object marker.object3d = new THREE.Object3D(); marker.object3d.matrixAutoUpdate = false; scene.add(marker.object3d); //UPDATE ARRAY HOLDING CURRENT MARKERS console.log("ON CREATE"); console.log("current detected markers: " + currentMarkers); var idx = currentMarkers.indexOf(markerId); // Find the index console.log("marker " + event.markerId + " has index: " + idx); if(idx==-1) // if does not exist currentMarkers.push(markerId); But this doesnt... var onDelete = function (event) { console.assert(markers[event.markerId] !== undefined); var markerId = event.markerId; //UPDATE ARRAY HOLDING CURRENT MARKERS console.log("ON DELETE"); console.log("current detected markers: " + currentMarkers); var idxx = currentMarkers.indexOf(markerId); // Find the index console.log("marker " + markerId + " has index: " + idxx); if(idxx != -1) {// if DOES exist currentMarkers.splice(idxx, 1); //Delete var idxxx = currentMarkersCoverChecked.indexOf(markerId); // Find the index if(idxxx == -1) // if does NOT exist, so if not being checked checkMarkerCovered(markerId); } onDeleteRandom(markerId); var marker = markers[markerId]; scene.remove(marker.object3d); delete markers[markerId]; Look at my console output: ON CREATE current detected markers: 2,1,4 marker 3 has index: -1 ON CREATE main.js:266 current detected markers: 2,1,4,3 marker 4 has index: 2 ON DELETE current detected markers: 2,1,4,3 marker 2 has index: -1 ON CREATE current detected markers: 2,1,4,3 marker 2 has index: 0 ON DELETE current detected markers: 2,1,4,3 marker 1 has index: -1

    Read the article

  • jquery indexOf problem with IE

    - by user441365
    Hi, I have a multiple select field and a jquery function that checks for a change in the select. the function looks for the value "Other", and if it's selected then displays an extra text field. This is all working fine in chrome and FF, but for some reason IE throws an error on the indexOf function "Object doesn't support this property or method". Any help would be much appreciated. Here's the code: <select name="test" multiple="multiple" id="test"> <option value="one">one</option> <option value="two">two</option> <option selected="selected" value="Other">Other</option> </select> <input name="Name_Other" type="text" id="Name_Other" class="OtherDisplay" /> $.toggleOther = function (dd, txtOther) { if ($(dd).val() == null || $(dd).val().indexOf("Other") != 1) $(txtOther).hide(); $(dd).change(function () { var sel = $(this).val(); if (sel != null && sel.indexOf("Other") != -1) { $(txtOther).show(); } else { $(txtOther).hide(); } }); } $.toggleOther("#test", ".OtherDisplay");

    Read the article

  • jquery split() and indexOf results in "Object doesn't support this property or method"

    - by chris
    I have the following code: var selected = $('#hiddenField').val().split(","); ... if (selected.indexOf(id) > 0) { ... set value ... } I'm dynamically creating a CheckBoxList, and trying to remember the state of the checkboxes by putting the selected IDs into the hidden field. I get an error stating that "Object doesn't support this property or method". My assumption is that selected is an array, which should support indexOf. Is that incorrect?

    Read the article

  • To not iterate through function of Array object if it is added to Array prototype

    - by Rishat Muhametshin
    According to the way to add indexOf method to Array class in IE6, how do I now reject this method from iterating through any random array? For example: Array.prototype.indexOf = function(needle) { ... }; var array = [1, 2, 3]; for (var i in array) { document.write(i + ': ' + array[i]); } gives output 0: 1 1: 2 2: 3 indexOf: function ... How can I skip indexOf property and stop iterating on it without adding any code to where for(...) is called?

    Read the article

  • Fixing javascript Array functions in Internet Explorer (indexOf, forEach, etc)

    - by Chas Emerick
    As detailed elsewhere, and otherwise apparently well-known, Internet Explorer (definitely 7, and in some instances, 8) do not implement key functions, in particular on Array (such as forEach, indexOf, etc). There are a number of workarounds here and there, but I'd like to fold a proper, canonical set of implementations into our site rather than copy and paste or hack away at our own implementations. I've found js-methods, which looks promising, but thought I'd post here to see whether another library comes more highly-recommended. A couple of misc. criteria: the lib should just be a no-op for those functions that a browser already has implementations for (js-methods appears to do quite well here) non-GPL, please, though LGPL is acceptable

    Read the article

  • Actionscript 3 while loop with indexOf

    - by Hanpan
    Hi, Is there any reason why this loop is getting stuck? I can't quite get my head around it: var i:Number = -1; do { i = Math.round(Math.random() * _totalQuestions); } while(_usedQuestions.indexOf(i)); Where _usedQuestions is an array of numbers. This array starts empty. Thanks! Edit: I want the loop to end if i is NOT found in the array.. this way I know the question I have selected has not previously been asked.

    Read the article

  • jQuery indexOf select box manipulation

    - by kenny99
    Hi, I'm trying to figure out how to remove options from a select box when that option has been selected in an adjacent select box. Basically the user has the option to add multiple records here via select boxes, but I want to remove the list of options available to them so that, for example, they can't enter the same value in two select boxes. When an Add More button is clicked, I fade in the next select box container. A number of select boxes have been generated by PHP and I use JS to hide them. Each select box has a unique number appended to the ID, so i want to access those select boxes which contain the string "other_pet_types", then I want to iterate through the currently visible ones and build an array of the values which have been selected, which I will then remove from the list of options in the newly displayed select box. This is what I have so far, but it's definitely not right - I can't get the initial test on the ID to work. Any pointers greatly appreciated as i realise i'm pretty wide of the mark at the moment! var vals = new Array(); //build array with currently selected options $('p.mult_entries select').each(function(){ vals += $(this).val(); }); $("p.mult_entries:hidden:first").fadeIn("slow", function() { $(this).find(('select').attr('id').indexOf('other_pet_types') > 0).each(function(){ console.log($(this).val()); //as expected prints nothing - need to iterate through the options of the above select //once i extract the correct values, iterate through new select box and use inArray to remove options where that value already exists in one of previous select boxes }); });

    Read the article

  • Angularjs throws TypeError: Cannot read property 'indexOf' of undefined

    - by Ali
    I'm trying to debug the above code which I feel like this is very useful .< I can't even find what is wrong in my code and don't really know where to start since Angularjs still very new to me. I'm trying to localize Angularjs app. I know this is missing a lot of context in order to get a help, but I'm trying to see what information that I should give that would help on this debugging. I've gone through any indexOf in angularjs file and I can see few things is undefined but don't know if that would be helpful. So I've traced the problem here and this is what I have figured is the problem, but still counldn't figure out why... config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) { $routeProvider.when('/:locale?/:username/badges', { templateUrl: '_partials/badges.html', controller: 'badges' }) .when('/:username/badges', { templateUrl: '_partials/badges.html', controller: 'badges' }) .when('/:username/teaching-resources', { templateUrl: '_partials/teaching-resources.html', controller: 'teachingResources' }) .when('/:username/makes', { templateUrl: '_partials/makes.html', controller: 'makes' }) .when('/:username/likes', { templateUrl: '_partials/likes.html', controller: 'likes' }) .when('/:username/events', { templateUrl: '_partials/events.html', controller: 'events' }) .when('/:username', { templateUrl: '_partials/badges.html', controller: 'badges' }); $routeProvider.otherwise({ redirectTo: '/error/404' }); The URL that I'm visiting for default page is: This will fail and throw the error. http://localhost:1969/en-US/user/someUserName This will work fine http://localhost:1969/user/someUserName UPDATE I figured out! This is the problem: $locationProvider.html5Mode(true); But why!?

    Read the article

  • C#: String.IndexOf to FileStream.Seek

    - by pistacchio
    Hi, having a FileStream that I read with a StreamReader (it is a very large file), how can I set the Seek position of the FileStream to the first occurrence of a certain substring so that I can start reading this large file from a given point? Thanks

    Read the article

  • Logging Into a site that uses Live.com authentication with C#

    - by Josh
    I've been trying to automate a log in to a website I frequent, www.bungie.net. The site is associated with Microsoft and Xbox Live, and as such makes uses of the Windows Live ID API when people log in to their site. I am relatively new to creating web spiders/robots, and I worry that I'm misunderstanding some of the most basic concepts. I've simulated logins to other sites such as Facebook and Gmail, but live.com has given me nothing but trouble. Anyways, I've been using Wireshark and the Firefox addon Tamper Data to try and figure out what I need to post, and what cookies I need to include with my requests. As far as I know these are the steps one must follow to log in to this site. 1. Visit https: //login.live.com/login.srf?wa=wsignin1.0&rpsnv=11&ct=1268167141&rver=5.5.4177.0&wp=LBI&wreply=http:%2F%2Fwww.bungie.net%2FDefault.aspx&id=42917 2. Recieve the cookies MSPRequ and MSPOK. 3. Post the values from the form ID "PPSX", the values from the form ID "PPFT", your username, your password all to a changing URL similar to: https: //login.live.com/ppsecure/post.srf?wa=wsignin1.0&rpsnv=11&ct= (there are a few numbers that change at the end of that URL) 4. Live.com returns the user a page with more hidden forms to post. The client then posts the values from the form "ANON", the value from the form "ANONExp" and the values from the form "t" to the URL: http ://www.bung ie.net/Default.aspx?wa=wsignin1.0 5. After posting that data, the user is returned a variety of cookies the most important of which is "BNGAuth" which is the log in cookie for the site. Where I am having trouble is on fifth step, but that doesn't neccesarily mean I've done all the other steps correctly. I post the data from "ANON", "ANONExp" and "t" but instead of being returned a BNGAuth cookie, I'm returned a cookie named "RSPMaybe" and redirected to the home page. When I review the Wireshark log, I noticed something that instantly stood out to me as different between the log when I logged in with Firefox and when my program ran. It could be nothing but I'll include the picture here for you to review. I'm being returned an HTTP packet from the site before I post the data in the fourth step. I'm not sure how this is happening, but it must be a side effect from something I'm doing wrong in the HTTPS steps. ![alt text][1] http://img391.imageshack.us/img391/6049/31394881.gif using System; using System.Collections.Generic; using System.Collections.Specialized; using System.Text; using System.Net; using System.IO; using System.IO.Compression; using System.Security.Cryptography; using System.Security.Cryptography.X509Certificates; using System.Web; namespace SpiderFromScratch { class Program { static void Main(string[] args) { CookieContainer cookies = new CookieContainer(); Uri url = new Uri("https://login.live.com/login.srf?wa=wsignin1.0&rpsnv=11&ct=1268167141&rver=5.5.4177.0&wp=LBI&wreply=http:%2F%2Fwww.bungie.net%2FDefault.aspx&id=42917"); HttpWebRequest http = (HttpWebRequest)HttpWebRequest.Create(url); http.Timeout = 30000; http.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.8) Gecko/20100202 Firefox/3.5.8 (.NET CLR 3.5.30729)"; http.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; http.Headers.Add("Accept-Language", "en-us,en;q=0.5"); http.Headers.Add("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7"); http.Headers.Add("Keep-Alive", "300"); http.Referer = "http://www.bungie.net/"; http.ContentType = "application/x-www-form-urlencoded"; http.CookieContainer = new CookieContainer(); http.Method = WebRequestMethods.Http.Get; HttpWebResponse response = (HttpWebResponse)http.GetResponse(); StreamReader readStream = new StreamReader(response.GetResponseStream()); string HTML = readStream.ReadToEnd(); readStream.Close(); //gets the cookies (they are set in the eighth header) string[] strCookies = response.Headers.GetValues(8); response.Close(); string name, value; Cookie manualCookie; for (int i = 0; i < strCookies.Length; i++) { name = strCookies[i].Substring(0, strCookies[i].IndexOf("=")); value = strCookies[i].Substring(strCookies[i].IndexOf("=") + 1, strCookies[i].IndexOf(";") - strCookies[i].IndexOf("=") - 1); manualCookie = new Cookie(name, "\"" + value + "\""); Uri manualURL = new Uri("http://login.live.com"); http.CookieContainer.Add(manualURL, manualCookie); } //stores the cookies to be used later cookies = http.CookieContainer; //Get the PPSX value string PPSX = HTML.Remove(0, HTML.IndexOf("PPSX")); PPSX = PPSX.Remove(0, PPSX.IndexOf("value") + 7); PPSX = PPSX.Substring(0, PPSX.IndexOf("\"")); //Get this random PPFT value string PPFT = HTML.Remove(0, HTML.IndexOf("PPFT")); PPFT = PPFT.Remove(0, PPFT.IndexOf("value") + 7); PPFT = PPFT.Substring(0, PPFT.IndexOf("\"")); //Get the random URL you POST to string POSTURL = HTML.Remove(0, HTML.IndexOf("https://login.live.com/ppsecure/post.srf?wa=wsignin1.0&rpsnv=11&ct=")); POSTURL = POSTURL.Substring(0, POSTURL.IndexOf("\"")); //POST with cookies http = (HttpWebRequest)HttpWebRequest.Create(POSTURL); http.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.8) Gecko/20100202 Firefox/3.5.8 (.NET CLR 3.5.30729)"; http.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; http.Headers.Add("Accept-Language", "en-us,en;q=0.5"); http.Headers.Add("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7"); http.Headers.Add("Keep-Alive", "300"); http.CookieContainer = cookies; http.Referer = "https://login.live.com/login.srf?wa=wsignin1.0&rpsnv=11&ct=1268158321&rver=5.5.4177.0&wp=LBI&wreply=http:%2F%2Fwww.bungie.net%2FDefault.aspx&id=42917"; http.ContentType = "application/x-www-form-urlencoded"; http.Method = WebRequestMethods.Http.Post; Stream ostream = http.GetRequestStream(); //used to convert strings into bytes System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding(); //Post information byte[] buffer = encoding.GetBytes("PPSX=" + PPSX +"&PwdPad=IfYouAreReadingThisYouHaveTooMuc&login=YOUREMAILGOESHERE&passwd=YOURWORDGOESHERE" + "&LoginOptions=2&PPFT=" + PPFT); ostream.Write(buffer, 0, buffer.Length); ostream.Close(); HttpWebResponse response2 = (HttpWebResponse)http.GetResponse(); readStream = new StreamReader(response2.GetResponseStream()); HTML = readStream.ReadToEnd(); response2.Close(); ostream.Dispose(); foreach (Cookie cookie in response2.Cookies) { Console.WriteLine(cookie.Name + ": "); Console.WriteLine(cookie.Value); Console.WriteLine(cookie.Expires); Console.WriteLine(); } //SET POSTURL value string POSTANON = "http://www.bungie.net/Default.aspx?wa=wsignin1.0"; //Get the ANON value string ANON = HTML.Remove(0, HTML.IndexOf("ANON")); ANON = ANON.Remove(0, ANON.IndexOf("value") + 7); ANON = ANON.Substring(0, ANON.IndexOf("\"")); ANON = HttpUtility.UrlEncode(ANON); //Get the ANONExp value string ANONExp = HTML.Remove(0, HTML.IndexOf("ANONExp")); ANONExp = ANONExp.Remove(0, ANONExp.IndexOf("value") + 7); ANONExp = ANONExp.Substring(0, ANONExp.IndexOf("\"")); ANONExp = HttpUtility.UrlEncode(ANONExp); //Get the t value string t = HTML.Remove(0, HTML.IndexOf("id=\"t\"")); t = t.Remove(0, t.IndexOf("value") + 7); t = t.Substring(0, t.IndexOf("\"")); t = HttpUtility.UrlEncode(t); //POST the Info and Accept the Bungie Cookies http = (HttpWebRequest)HttpWebRequest.Create(POSTANON); http.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.8) Gecko/20100202 Firefox/3.5.8 (.NET CLR 3.5.30729)"; http.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; http.Headers.Add("Accept-Language", "en-us,en;q=0.5"); http.Headers.Add("Accept-Encoding", "gzip,deflate"); http.Headers.Add("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7"); http.Headers.Add("Keep-Alive", "115"); http.CookieContainer = new CookieContainer(); http.ContentType = "application/x-www-form-urlencoded"; http.Method = WebRequestMethods.Http.Post; http.Expect = null; ostream = http.GetRequestStream(); int test = ANON.Length; int test1 = ANONExp.Length; int test2 = t.Length; buffer = encoding.GetBytes("ANON=" + ANON +"&ANONExp=" + ANONExp + "&t=" + t); ostream.Write(buffer, 0, buffer.Length); ostream.Close(); //Here lies the problem, I am not returned the correct cookies. HttpWebResponse response3 = (HttpWebResponse)http.GetResponse(); GZipStream gzip = new GZipStream(response3.GetResponseStream(), CompressionMode.Decompress); readStream = new StreamReader(gzip); HTML = readStream.ReadToEnd(); //gets both cookies string[] strCookies2 = response3.Headers.GetValues(11); response3.Close(); } } } This has given me problems and I've put many hours into learning about HTTP protocols so any help would be appreciated. If there is an article detailing a similar log in to live.com feel free to point the way. I've been looking far and wide for any articles with working solutions. If I could be clearer, feel free to ask as this is my first time using Stack Overflow. Cheers, --Josh

    Read the article

  • Logging Into a site that uses Live.com authentication

    - by Josh
    I've been trying to automate a log in to a website I frequent, www.bungie.net. The site is associated with Microsoft and Xbox Live, and as such makes uses of the Windows Live ID API when people log in to their site. I am relatively new to creating web spiders/robots, and I worry that I'm misunderstanding some of the most basic concepts. I've simulated logins to other sites such as Facebook and Gmail, but live.com has given me nothing but trouble. Anyways, I've been using Wireshark and the Firefox addon Tamper Data to try and figure out what I need to post, and what cookies I need to include with my requests. As far as I know these are the steps one must follow to log in to this site. 1. Visit https: //login.live.com/login.srf?wa=wsignin1.0&rpsnv=11&ct=1268167141&rver=5.5.4177.0&wp=LBI&wreply=http:%2F%2Fwww.bungie.net%2FDefault.aspx&id=42917 2. Recieve the cookies MSPRequ and MSPOK. 3. Post the values from the form ID "PPSX", the values from the form ID "PPFT", your username, your password all to a changing URL similar to: https: //login.live.com/ppsecure/post.srf?wa=wsignin1.0&rpsnv=11&ct= (there are a few numbers that change at the end of that URL) 4. Live.com returns the user a page with more hidden forms to post. The client then posts the values from the form "ANON", the value from the form "ANONExp" and the values from the form "t" to the URL: http ://www.bung ie.net/Default.aspx?wa=wsignin1.0 5. After posting that data, the user is returned a variety of cookies the most important of which is "BNGAuth" which is the log in cookie for the site. Where I am having trouble is on fifth step, but that doesn't neccesarily mean I've done all the other steps correctly. I post the data from "ANON", "ANONExp" and "t" but instead of being returned a BNGAuth cookie, I'm returned a cookie named "RSPMaybe" and redirected to the home page. When I review the Wireshark log, I noticed something that instantly stood out to me as different between the log when I logged in with Firefox and when my program ran. It could be nothing but I'll include the picture here for you to review. I'm being returned an HTTP packet from the site before I post the data in the fourth step. I'm not sure how this is happening, but it must be a side effect from something I'm doing wrong in the HTTPS steps. using System; using System.Collections.Generic; using System.Collections.Specialized; using System.Text; using System.Net; using System.IO; using System.IO.Compression; using System.Security.Cryptography; using System.Security.Cryptography.X509Certificates; using System.Web; namespace SpiderFromScratch { class Program { static void Main(string[] args) { CookieContainer cookies = new CookieContainer(); Uri url = new Uri("https://login.live.com/login.srf?wa=wsignin1.0&rpsnv=11&ct=1268167141&rver=5.5.4177.0&wp=LBI&wreply=http:%2F%2Fwww.bungie.net%2FDefault.aspx&id=42917"); HttpWebRequest http = (HttpWebRequest)HttpWebRequest.Create(url); http.Timeout = 30000; http.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.8) Gecko/20100202 Firefox/3.5.8 (.NET CLR 3.5.30729)"; http.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; http.Headers.Add("Accept-Language", "en-us,en;q=0.5"); http.Headers.Add("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7"); http.Headers.Add("Keep-Alive", "300"); http.Referer = "http://www.bungie.net/"; http.ContentType = "application/x-www-form-urlencoded"; http.CookieContainer = new CookieContainer(); http.Method = WebRequestMethods.Http.Get; HttpWebResponse response = (HttpWebResponse)http.GetResponse(); StreamReader readStream = new StreamReader(response.GetResponseStream()); string HTML = readStream.ReadToEnd(); readStream.Close(); //gets the cookies (they are set in the eighth header) string[] strCookies = response.Headers.GetValues(8); response.Close(); string name, value; Cookie manualCookie; for (int i = 0; i < strCookies.Length; i++) { name = strCookies[i].Substring(0, strCookies[i].IndexOf("=")); value = strCookies[i].Substring(strCookies[i].IndexOf("=") + 1, strCookies[i].IndexOf(";") - strCookies[i].IndexOf("=") - 1); manualCookie = new Cookie(name, "\"" + value + "\""); Uri manualURL = new Uri("http://login.live.com"); http.CookieContainer.Add(manualURL, manualCookie); } //stores the cookies to be used later cookies = http.CookieContainer; //Get the PPSX value string PPSX = HTML.Remove(0, HTML.IndexOf("PPSX")); PPSX = PPSX.Remove(0, PPSX.IndexOf("value") + 7); PPSX = PPSX.Substring(0, PPSX.IndexOf("\"")); //Get this random PPFT value string PPFT = HTML.Remove(0, HTML.IndexOf("PPFT")); PPFT = PPFT.Remove(0, PPFT.IndexOf("value") + 7); PPFT = PPFT.Substring(0, PPFT.IndexOf("\"")); //Get the random URL you POST to string POSTURL = HTML.Remove(0, HTML.IndexOf("https://login.live.com/ppsecure/post.srf?wa=wsignin1.0&rpsnv=11&ct=")); POSTURL = POSTURL.Substring(0, POSTURL.IndexOf("\"")); //POST with cookies http = (HttpWebRequest)HttpWebRequest.Create(POSTURL); http.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.8) Gecko/20100202 Firefox/3.5.8 (.NET CLR 3.5.30729)"; http.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; http.Headers.Add("Accept-Language", "en-us,en;q=0.5"); http.Headers.Add("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7"); http.Headers.Add("Keep-Alive", "300"); http.CookieContainer = cookies; http.Referer = "https://login.live.com/login.srf?wa=wsignin1.0&rpsnv=11&ct=1268158321&rver=5.5.4177.0&wp=LBI&wreply=http:%2F%2Fwww.bungie.net%2FDefault.aspx&id=42917"; http.ContentType = "application/x-www-form-urlencoded"; http.Method = WebRequestMethods.Http.Post; Stream ostream = http.GetRequestStream(); //used to convert strings into bytes System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding(); //Post information byte[] buffer = encoding.GetBytes("PPSX=" + PPSX +"&PwdPad=IfYouAreReadingThisYouHaveTooMuc&login=YOUREMAILGOESHERE&passwd=YOURWORDGOESHERE" + "&LoginOptions=2&PPFT=" + PPFT); ostream.Write(buffer, 0, buffer.Length); ostream.Close(); HttpWebResponse response2 = (HttpWebResponse)http.GetResponse(); readStream = new StreamReader(response2.GetResponseStream()); HTML = readStream.ReadToEnd(); response2.Close(); ostream.Dispose(); foreach (Cookie cookie in response2.Cookies) { Console.WriteLine(cookie.Name + ": "); Console.WriteLine(cookie.Value); Console.WriteLine(cookie.Expires); Console.WriteLine(); } //SET POSTURL value string POSTANON = "http://www.bungie.net/Default.aspx?wa=wsignin1.0"; //Get the ANON value string ANON = HTML.Remove(0, HTML.IndexOf("ANON")); ANON = ANON.Remove(0, ANON.IndexOf("value") + 7); ANON = ANON.Substring(0, ANON.IndexOf("\"")); ANON = HttpUtility.UrlEncode(ANON); //Get the ANONExp value string ANONExp = HTML.Remove(0, HTML.IndexOf("ANONExp")); ANONExp = ANONExp.Remove(0, ANONExp.IndexOf("value") + 7); ANONExp = ANONExp.Substring(0, ANONExp.IndexOf("\"")); ANONExp = HttpUtility.UrlEncode(ANONExp); //Get the t value string t = HTML.Remove(0, HTML.IndexOf("id=\"t\"")); t = t.Remove(0, t.IndexOf("value") + 7); t = t.Substring(0, t.IndexOf("\"")); t = HttpUtility.UrlEncode(t); //POST the Info and Accept the Bungie Cookies http = (HttpWebRequest)HttpWebRequest.Create(POSTANON); http.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.8) Gecko/20100202 Firefox/3.5.8 (.NET CLR 3.5.30729)"; http.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; http.Headers.Add("Accept-Language", "en-us,en;q=0.5"); http.Headers.Add("Accept-Encoding", "gzip,deflate"); http.Headers.Add("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7"); http.Headers.Add("Keep-Alive", "115"); http.CookieContainer = new CookieContainer(); http.ContentType = "application/x-www-form-urlencoded"; http.Method = WebRequestMethods.Http.Post; http.Expect = null; ostream = http.GetRequestStream(); int test = ANON.Length; int test1 = ANONExp.Length; int test2 = t.Length; buffer = encoding.GetBytes("ANON=" + ANON +"&ANONExp=" + ANONExp + "&t=" + t); ostream.Write(buffer, 0, buffer.Length); ostream.Close(); //Here lies the problem, I am not returned the correct cookies. HttpWebResponse response3 = (HttpWebResponse)http.GetResponse(); GZipStream gzip = new GZipStream(response3.GetResponseStream(), CompressionMode.Decompress); readStream = new StreamReader(gzip); HTML = readStream.ReadToEnd(); //gets both cookies string[] strCookies2 = response3.Headers.GetValues(11); response3.Close(); } } } This has given me problems and I've put many hours into learning about HTTP protocols so any help would be appreciated. If there is an article detailing a similar log in to live.com feel free to point the way. I've been looking far and wide for any articles with working solutions. If I could be clearer, feel free to ask as this is my first time using Stack Overflow.

    Read the article

  • simplfy javascript code using regex

    - by Pradyut Bhattacharya
    Hi I have a code which can show youtube videos if there are any links to youtube in the text like for example the text example at:- pradyut.dyndns.org http://www.youtube.com/watch?v=-LiPMxFBLZY testing http://www.youtube.com/watch?v=Q3-l22b_Qg8&feature=related this text i m forwarding to the function... function to_youtubelink(text) { if ( text.indexOf ('<') > 0 || text.indexOf ('"') > 0 || text.indexOf ('>') > 0 ) return text; else { var obj_text = new Array(); var oi = 0; while(text.indexOf('http://') >=0) { //getting the paths var si = text.indexOf('http://'); var gr = text.indexOf('\n', si); var sp = text.indexOf(' ', si); var ei; if ( gr > 0 || sp > 0 ) { if ( gr >0 && sp > 0 ) { if ( gr < sp ) { ei = gr ; } else { ei = sp ; } } else if ( gr > 0) { ei = gr; } else { ei = sp; } } else { ei = text.length; } var it = text.substring(si,ei); if ( it.indexOf('"') > 0) { it.substring(0, it.indexOf('"') ); } if(ei < 0) ei = text.length; else ei = text.indexOf(' ', si) ; obj_text[oi] = it; text = text.replace( it, '[link_service]'); oi++; } var ob_text = new Array(); var ob =0; for (oi=0; oi<obj_text.length; oi++) { if ( is_youtubelink( obj_text[oi] ) ) { ob_text[ob] = to_utubelink(obj_text[oi]); ob++; } } oi = 0; while ( text.indexOf('[link_service]') >=0 ) { text = text.replace( '[link_service]', obj_text[oi]); oi ++; } for (ob=0; ob<ob_text.length; ob++) { text = text +"\n\n" + ob_text[ob]; } return text; } } function is_youtubelink(text) { var matches = text.match(/http:\/\/(?:www\.)?youtube.*watch\?v=([a-zA-Z0-9\-_]+)/); if (matches) { return true; } else { return false; } } function to_utubelink(text) { var video_id = text.split('v=')[1]; var ampersandPosition = video_id.indexOf('&'); if(ampersandPosition != -1) { video_id = video_id.substring(0, ampersandPosition); } text = "<iframe title=\"YouTube video player\" class=\"youtube-player\" type=\"text/html\" width=\"425\" height=\"350\" src=\"http://www.youtube.com/embed/" + video_id + "\" frameborder=\"0\"></iframe>" return text; } now i m getting the output properly... but i was thinking if the code could be done better and simplified using regex ...especially getting the urls part... thanks

    Read the article

1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >