public bool SetProfilePic(ref GlobusHttpHelper HttpHelper, string profileId, string Username, string Password, string localImagePath, string proxyAddress, string proxyPort, string proxyUsername, string proxyPassword, ref string status, string UploadInfoData) { string FirstGetREsponse = string.Empty; try { FirstGetREsponse = HttpHelper.getHtmlfromUrl(new Uri("http://www.linkedin.com/profile/edit-picture-info?trk=prof-ovw-edit-photo")); } catch { } if (string.IsNullOrEmpty(FirstGetREsponse)) { try { FirstGetREsponse = HttpHelper.getHtmlfromUrl(new Uri("https://www.linkedin.com/profile/edit-picture-info?goback=%2Enpv_" + profileId + "_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1&trk=prof-ovw-edit-photo")); } catch { } } string[] upload_infoArr = Regex.Split(FirstGetREsponse, " name=\"upload_info"); string upload_infow = string.Empty; string upload_infowithjs = string.Empty; if (true) { try { upload_infow = upload_infoArr[1].Substring(upload_infoArr[1].IndexOf("value="), upload_infoArr[1].IndexOf(">") - upload_infoArr[1].IndexOf("value=")).Replace("value=", string.Empty).Replace("\"", string.Empty).Replace("\\", string.Empty).Replace("/", string.Empty).Trim(); } catch { } try { upload_infowithjs = upload_infoArr[2].Substring(upload_infoArr[2].IndexOf("value="), upload_infoArr[2].IndexOf(">") - upload_infoArr[2].IndexOf("value=")).Replace("value=", string.Empty).Replace("\"", string.Empty).Replace("\\", string.Empty).Replace("/", string.Empty).Trim(); } catch { } } else { //try //{ // string[] upload_infoArr1 = Regex.Split(FirstGetREsponse, "id\":\"upload_info"); // upload_infow = upload_infoArr1[1].Substring(upload_infoArr1[1].IndexOf("value\":"), upload_infoArr1[1].IndexOf("type") - upload_infoArr1[1].IndexOf("value\":")).Replace("value\":", string.Empty).Replace("\"", string.Empty).Replace("\\", string.Empty).Replace(",", string.Empty).Trim(); //} //catch { } } string posturi = string.Empty; if (FirstGetREsponse.Contains("name=\"uploadMemberPicture")) { try { string[] MemberPicture = Regex.Split(FirstGetREsponse, "name=\"uploadMemberPicture"); posturi = MemberPicture[1].Substring(MemberPicture[1].IndexOf("action="), MemberPicture[1].IndexOf("method=") - MemberPicture[1].IndexOf("action=")).Replace("action=", string.Empty).Replace("\"", string.Empty).Replace("\\", string.Empty).Replace("/", string.Empty).Trim(); } catch { } } bool isSetProfilePic = false; try { string upload_info = ""; upload_info = upload_infow; string upload_info_with_js = ""; upload_info_with_js = upload_infowithjs; //upload_info = upload_info.Replace("&dsh;", "-"); ; //upload_info_with_js = upload_info; string callback = ""; callback = "profilePicture.processResponse"; NameValueCollection nvc = new NameValueCollection(); nvc.Add("upload_info", upload_info_with_js); nvc.Add("upload_info_with_js", upload_info_with_js); nvc.Add("callback", callback); //nvc.Add("Content-Type:", "image/jpeg"); posturi = posturi.Replace("mupld", string.Empty); //string response = HttpHelper.HttpUploadProfilePic(ref HttpHelper, profileId, "http://www.linkedin.com/mupld/" + posturi, "pic", "image/jpeg", localImagePath, nvc, proxyAddress, Convert.ToInt32(proxyPort), proxyUsername, proxyPassword); string response = string.Empty; try { response = HttpHelper.HttpUploadProfilePic(ref HttpHelper, profileId, "http://www.linkedin.com/mupld/upload", "pic", "image/jpeg", localImagePath, nvc, proxyAddress, Convert.ToInt32(proxyPort), proxyUsername, proxyPassword); } catch { } if (string.IsNullOrEmpty(response)) { response = HttpHelper.HttpUploadProfilePic(ref HttpHelper, profileId, "https://www.linkedin.com/mupld/upload?goback=%2Enpv_" + profileId + "_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1", "pic", "image/jpeg", localImagePath, nvc, proxyAddress, Convert.ToInt32(proxyPort), proxyUsername, proxyPassword); //http://www.linkedin.com/mupld/process?filter=car450&return_type=html&mid=%2Fp/6/005/025/1b7/34bf4a0.jpg&callback=profilePicture.savePhoto&filters_scale_h=397&filters_scale_w=600&filters_crop_x=101&filters_crop_y=0&filters_crop_h=396.99966&filters_crop_w=396.99966&filters_rotate_t= } string Images1 = string.Empty; if (response.Contains("SUCCESS")) { try { Images1 = response.Substring(response.IndexOf("value\":"), response.IndexOf("}") - response.IndexOf("value\":")).Replace("value\":", string.Empty).Replace("\"", string.Empty).Replace("\\", string.Empty).Trim(); Images1 = Images1.Substring(1, (Images1.Length - 1)); Images1 = Images1.Remove(Images1.IndexOf(",")); Images1 = "/" + Images1; } catch { } } string csrfToken = string.Empty; string sourceAlias = string.Empty; if (FirstGetREsponse.Contains("csrfToken")) { try { int startindex = FirstGetREsponse.IndexOf("csrfToken"); if (startindex > 0) { string start = FirstGetREsponse.Substring(startindex); int endindex = start.IndexOf("\">"); string end = start.Substring(0, endindex); csrfToken = end.Replace("csrfToken=", "").Replace("\\", ""); } else { string[] Arr = csrfToken.Split('"'); csrfToken = Arr[2].Replace("\\", string.Empty); } } catch { try { csrfToken = FirstGetREsponse.Substring(FirstGetREsponse.IndexOf("csrfToken"), 100); if (csrfToken.Contains("&")) { string[] Arr = csrfToken.Split('&'); csrfToken = Arr[0]; } else if (csrfToken.Contains(",")) { string[] Arr = csrfToken.Split(','); csrfToken = Arr[0].Replace("\\", string.Empty); } else { string[] Arr = csrfToken.Split(','); csrfToken = Arr[0].Replace("\\", string.Empty).Replace("csrfToken=", "").Replace("\n", "").Replace("\">", ""); } } catch { } } } if (FirstGetREsponse.Contains("sourceAlias")) { try { sourceAlias = FirstGetREsponse.Substring(FirstGetREsponse.IndexOf("sourceAlias"), 100); string[] Arr = sourceAlias.Split('"'); sourceAlias = Arr[2].Replace("\\", string.Empty); } catch { } } if (string.IsNullOrEmpty(sourceAlias)) { if (FirstGetREsponse.Contains("sourceAlias")) { try { sourceAlias = FirstGetREsponse.Substring(FirstGetREsponse.IndexOf("sourceAlias"), 100); string[] Arr = sourceAlias.Split('"'); sourceAlias = Arr[2]; } catch { } } } string Images = string.Empty; string FirstGet = string.Empty; string setMaskWidth = string.Empty; string setMaskHeight = string.Empty; string setMaskTop = string.Empty; string setMaskLeft = string.Empty; string setCropFilter = string.Empty; if (FirstGetREsponse.Contains("profilePicture.setMaskWidth")) { try { string[] setMaskWidthArr = Regex.Split(FirstGetREsponse, "profilePicture.setMaskWidth"); Match match = Regex.Match(setMaskWidthArr[1], @"\((.*?)\)"); if (match.Groups.Count > 1) { setMaskWidth = match.Groups[1].Value; } } catch { } } if (FirstGetREsponse.Contains("profilePicture.setMaskHeight")) { try { string[] setMaskHeightArr = Regex.Split(FirstGetREsponse, "profilePicture.setMaskHeight"); Match match = Regex.Match(setMaskHeightArr[1], @"\((.*?)\)"); if (match.Groups.Count > 1) { setMaskHeight = match.Groups[1].Value; } } catch { } } if (FirstGetREsponse.Contains("profilePicture.setMaskTop")) { try { string[] setMaskTopArr = Regex.Split(FirstGetREsponse, "profilePicture.setMaskTop"); Match match = Regex.Match(setMaskTopArr[1], @"\((.*?)\)"); if (match.Groups.Count > 1) { setMaskTop = match.Groups[1].Value; } } catch { } } if (FirstGetREsponse.Contains("profilePicture.setMaskLeft")) { try { string[] setMaskLeftArr = Regex.Split(FirstGetREsponse, "profilePicture.setMaskLeft"); Match match = Regex.Match(setMaskLeftArr[1], @"\((.*?)\)"); if (match.Groups.Count > 1) { setMaskLeft = match.Groups[1].Value; } } catch { } } if (FirstGetREsponse.Contains("profilePicture.setCropFilter")) { try { string[] setCropFilterArr = Regex.Split(FirstGetREsponse, "profilePicture.setCropFilter"); Match match = Regex.Match(setCropFilterArr[1], @"\((.*?)\)"); if (match.Groups.Count > 1) { setCropFilter = match.Groups[1].Value; } } catch { } } //profilePicture.setCropFilter try { // string FirstGet = HttpHelper.getHtmlfromUrl(new Uri("http://www.linkedin.com/mupld/process?goback=%2Enpv_" + profileId + "_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1&filter=car80&return_type=html&mid=%2Fp"+Images1+"&callback=profilePicture.savePhoto&filters_scale_h=80&filters_scale_w=335&filters_crop_x=0&filters_crop_y=0&filters_crop_h=335&filters_crop_w=335&filters_rotate_t=")); // string FirstGet = HttpHelper.getHtmlfromUrl(new Uri("https://www.linkedin.com/mupld/process?goback=%2Enpv_" + profileId + "_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1&filter=car80&return_type=html&mid=%2F" + Images1 + "&callback=profilePicture.savePhoto&filters_scale_h=80&filters_scale_w=346&filters_crop_x=0&filters_crop_y=0&filters_crop_h=346&filters_crop_w=346&filters_rotate_t=")); #region Setting Image Parameters float w = 200, h = 200; try { //GetJpegDimension(localImagePath, out h, out w); System.Drawing.Size sz = ImageHelper.GetDimensions(localImagePath); w = sz.Width; h = sz.Height; } catch { } float filters_scale_h = RandomNumberGenerator.GenerateRandom(187, 187); float filters_scale_w = RandomNumberGenerator.GenerateRandom(187, 187); int filters_crop_h = RandomNumberGenerator.GenerateRandom(187, 187); int filters_crop_w = filters_crop_h; if (w >= 3000) { w = 3000; } if (h >= 800) { h = 800; } float heightwidthratio = h / w; filters_scale_w = w; filters_scale_h = w * heightwidthratio; if (filters_scale_w < filters_scale_h) { filters_crop_w = (int)filters_scale_w; } else { filters_crop_w = (int)filters_scale_h - 5; } if (filters_crop_w > 350) { filters_crop_w = RandomNumberGenerator.GenerateRandom(187,187); } #endregion //if (string.IsNullOrEmpty(setMaskHeight)) { try { FirstGet = HttpHelper.getHtmlfromUrl(new Uri("http://www.linkedin.com/mupld/process?filter=" + "car450" + "&return_type=html&mid=" + Images1 + "&callback=profilePicture.savePhoto&filters_scale_h=" + (int)filters_scale_h + "&filters_scale_w=" + (int)filters_scale_w + "&filters_crop_x=0&filters_crop_y=0&filters_crop_h=" + filters_scale_h + "&filters_crop_w=" + filters_scale_h + "&filters_rotate_t="));//filters_crop_h=135&filters_crop_w=135&filters_rotate_t=")); if (string.IsNullOrEmpty(FirstGet)) { System.Threading.Thread.Sleep(500); FirstGet = HttpHelper.getHtmlfromUrl(new Uri("http://www.linkedin.com/mupld/process?filter=" + "car450" + "&return_type=html&mid=" + Images1 + "&callback=profilePicture.savePhoto&filters_scale_h=" + (int)filters_scale_h + "&filters_scale_w=" + (int)filters_scale_w + "&filters_crop_x=0&filters_crop_y=0&filters_crop_h=" + filters_crop_w + "&filters_crop_w=" + filters_crop_w + "&filters_rotate_t="));//filters_crop_h=135&filters_crop_w=135&filters_rotate_t=")); } //FirstGet = HttpHelper.getHtmlfromUrl(new Uri("http://www.linkedin.com/mupld/process?filter=" + "car450" + "&return_type=html&mid=" + Images1 + "&callback=profilePicture.savePhoto&filters_scale_h=" + 180 + "&filters_scale_w=" + 180 + "&filters_crop_x=0&filters_crop_y=0&filters_crop_h=" + 145 + "&filters_crop_w=" + 145 + "&filters_rotate_t="));//filters_crop_h=135&filters_crop_w=135&filters_rotate_t=")); string mid = ""; if (FirstGet.Contains("SUCCESS")) { try { mid = FirstGet.Substring(FirstGet.IndexOf("value\":"), FirstGet.IndexOf("}") - FirstGet.IndexOf("value\":")).Replace("value\":", string.Empty).Replace("\"", string.Empty).Replace("\\", string.Empty).Trim(); mid = mid.Substring(1, (mid.Length - 1)); //mid = mid.Remove(mid.IndexOf(",")); mid = "/" + mid; // Images = Uri.EscapeDataString(Images); } catch { } } string gup_savecroppic = HttpHelper.getHtmlfromUrl(new Uri("http://www.linkedin.com/profile/save-crop-picture?csrfToken=" + csrfToken + "&masterTempID=" + Images1 + "&croppedTempID=" + mid + "&xParam=0&yParam=0&xSizeParam=" + filters_crop_w + "&ySizeParam=" + filters_crop_w + "&nsave=n"));//xSizeParam=292&ySizeParam=292&nsave=n")); //string gup_savecroppic = HttpHelper.getHtmlfromUrl(new Uri("http://www.linkedin.com/profile/save-crop-picture?csrfToken=" + csrfToken + "&masterTempID=" + Images1 + "&croppedTempID=" + mid + "&xParam=0&yParam=0&xSizeParam=" + 135 + "&ySizeParam=" + 135 + "&nsave=n"));//xSizeParam=292&ySizeParam=292&nsave=n")); //http://www.linkedin.com/profile/edit-picture-info?trk=nprofile-save-picture-submit&report%2Esuccess=9dCbijuoBwCwpKulrwnkugn6gmZHePJOoeK5jlW7JYSHYSSp-w55jdor_TR6umL } catch { } #region Old code //if (string.IsNullOrEmpty(FirstGet)) //{ // try // { // FirstGet = HttpHelper.getHtmlfromUrl(new Uri("http://www.linkedin.com/mupld/process?goback=%2Enpv_" + profileId + "_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1&filter=car80&return_type=html&mid=%2F" + Images1 + "&callback=profilePicture.savePhoto&filters_scale_h=80&filters_scale_w=80&filters_crop_x=0&filters_crop_y=0&filters_crop_h=335&filters_crop_w=335&filters_rotate_t=")); // } // catch { } //} //if (FirstGet.Contains("SUCCESS")) //{ // try // { // Images = FirstGet.Substring(FirstGet.IndexOf("value\":"), FirstGet.IndexOf("}") - FirstGet.IndexOf("value\":")).Replace("value\":", string.Empty).Replace("\"", string.Empty).Replace("\\", string.Empty).Trim(); // Images = Images.Substring(1, (Images.Length - 1)); // // Images = Uri.EscapeDataString(Images); // } // catch { } //} #endregion } #region Old Code //else //{ // try // { // FirstGet = HttpHelper.getHtmlfromUrl(new Uri("http://www.linkedin.com/mupld/process?goback=%2Enpv_" + profileId + "_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1&filter=" + setCropFilter + "&return_type=html&mid=%2F" + Images1 + "&callback=profilePicture.savePhoto&filters_scale_h=" + setMaskHeight + "&filters_scale_w=" + setMaskWidth + "&filters_crop_x=" + setMaskLeft + "&filters_crop_y=" + setMaskTop + "&filters_crop_h=" + setMaskHeight + "&filters_crop_w=" + setMaskWidth + "&filters_rotate_t=")); // } // catch { } // if (string.IsNullOrEmpty(FirstGet)) // { // FirstGet = HttpHelper.getHtmlfromUrl(new Uri("https://www.linkedin.com/mupld/process?goback=%2Enpv_" + profileId + "_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1&filter=" + setCropFilter + "&return_type=html&mid=%2F" + Images1 + "&callback=profilePicture.savePhoto&filters_scale_h=80&filters_scale_w=80&filters_crop_x=" + setMaskLeft + "&filters_crop_y=" + setMaskTop + "&filters_crop_h=" + setMaskHeight + "&filters_crop_w=" + setMaskWidth + "&filters_rotate_t=")); // } // if (FirstGet.Contains("SUCCESS")) // { // try // { // Images = FirstGet.Substring(FirstGet.IndexOf("value\":"), FirstGet.IndexOf("}") - FirstGet.IndexOf("value\":")).Replace("value\":", string.Empty).Replace("\"", string.Empty).Replace("\\", string.Empty).Trim(); // Images = Images.Substring(1, (Images.Length - 1)); // // Images = Uri.EscapeDataString(Images); // } // catch { } // } // if (string.IsNullOrEmpty(FirstGet)) // { // try // { // FirstGet = HttpHelper.getHtmlfromUrl(new Uri("http://www.linkedin.com/mupld/process?goback=%2Enpv_" + profileId + "_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1&filter=car80&return_type=html&mid=%2F" + Images1 + "&callback=profilePicture.savePhoto&filters_scale_h=80&filters_scale_w=80&filters_crop_x=0&filters_crop_y=0&filters_crop_h=335&filters_crop_w=335&filters_rotate_t=")); // } // catch { } // } //} #endregion } catch { } #region Old code //string thirdresponse = string.Empty; //try //{ // string secondGetResponsee = string.Empty; // try // { // secondGetResponsee = HttpHelper.getHtmlfromUrl(new Uri("http://www.linkedin.com/profile/save-crop-picture?csrfToken=" + csrfToken + "&masterTempID=%2F" + Images + "&croppedTempID=%2F" + Images1 + "&xParam=0&yParam=0&xSizeParam=80&ySizeParam=80&nsave=n")); // } // catch { } // if (secondGetResponsee.Contains("name=\"currenturl")) // { // try // { // string[] currenturlArr = Regex.Split(secondGetResponsee, "name=\"currenturl"); // string currenturl = currenturlArr[1].Substring(currenturlArr[1].IndexOf("value=\""), currenturlArr[1].IndexOf(">") - currenturlArr[1].IndexOf("value=\"")).Replace("value=\"", string.Empty).Replace("\"", string.Empty).Replace("\\", string.Empty).Trim(); // currenturl = Uri.UnescapeDataString(currenturl); // currenturl = Regex.Split(currenturl, "&urlhash")[0]; // // string thirdresponse = HttpHelper.getHtmlfromUrl(new Uri("http://www.linkedin.com/profile/edit-picture-info?trk=nprofile-save-picture-submit&report%2Esuccess=9dCbijuoBwCwpKulrwnkugn6gmZHePJOoeK5jlW7JYSHYSSp-w55jdor_TR6umL")); // thirdresponse = HttpHelper.getHtmlfromUrl(new Uri(currenturl)); // } // catch { } // } //} //catch { } //try //{ // string postSavePictureData = "pictureVisibility=NETWORK&csrfToken=" + csrfToken + "&sourceAlias=" + sourceAlias + "&goback=.npv_" + profileId + "_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1.npe_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1"; // string PostSavePictureUrl = "http://www.linkedin.com/profile/edit-picture-visibility-submit"; // string responsess = HttpHelper.postFormData(new Uri(PostSavePictureUrl), postSavePictureData); // string GetResponse=HttpHelper.getHtmlfromUrl(new Uri("http://www.linkedin.com/profile/edit?goback=%2Enpv_"+profileId+"_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1%2Enpe_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1&trk=nprofile-save-picture-settings-submit&report%2Esuccess=88GfZh25oYpGMv_ncXhqwkk2axsD1cOiNrQErX7HNxy7raoMejQEhfBsYJTYoZpJLJh9oM")); //} //catch { } //try //{ // //string secondpostUrl="https://www.linkedin.com/mupld/upload?goback=%2Enpv_" + profileId + "_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1%2Enpe_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1"; // //string posturl = "pkey=PAGEKEY_PLACEHOLDER&tcode=ntf_click_notifications_icon&plist=alert_count%3A0&prefix=false"; // //string secondres=HttpHelper.postFormData(new Uri(secondpostUrl), posturl); //} //catch { } ////name="sourceAlias" #endregion if (!string.IsNullOrEmpty(FirstGet) && !string.IsNullOrEmpty(response)) { if (FirstGet.Contains("SUCCESS") && response.Contains("SUCCESS")) // && !thirdresponse.Contains("error") && !string.IsNullOrEmpty(response) && !response.Contains("error")) { isSetProfilePic = true; } if (!string.IsNullOrEmpty(response) && !response.Contains("error")) { } } else { return isSetProfilePic; } } catch { } return isSetProfilePic; }