Home .NET pass a variable to the second block of code
Reply: 0

.NET pass a variable to the second block of code

user2405 Published in June 21, 2018, 8:43 am

Very simple question though I'm pretty baffled, I found myself using this function a lot in my controllers so moved it to a method which is my first one. The foreach loop has a final string FinalURL how do I pass that into the httpWebRequest? do I make another method and call it after the break? Before i used a viewbag variable but in this context i cant use it. If i remove the brackets it says not all paths return a function and i believe this isn't the correct way.

namespace Linkofy.Models
public class MajesticFunctions
    public static int[] MajesticChecker(string[] URLtests)
        foreach (string URLt in URLtests)
            HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(URLt);
            myHttpWebRequest.AllowAutoRedirect = false;
            HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
            int resulting = (int)myHttpWebResponse.StatusCode;
            if (resulting == 200)
                String Urlnew = URLt;
                String FinalURL = URLt.Replace("https://", "").Replace("http://", "");
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://api.majestic.com/api/json?app_api_key=KEY&cmd=GetIndexItemInfo&items=1&item0=" + FinalURL + "&datasource=fresh");
            WebResponse response = request.GetResponse();
            using (Stream responseStream = response.GetResponseStream())
                StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
                JObject jObject = JObject.Parse(reader.ReadToEnd());
                JToken Trusty = jObject["DataTables"]["Results"]["Data"][0]["TrustFlow"].Value<int>();
                JToken City = jObject["DataTables"]["Results"]["Data"][0]["CitationFlow"].Value<int>();
                JToken RIPy = jObject["DataTables"]["Results"]["Data"][0]["RefIPs"].Value<int>();

                int Trustflow = Int32.Parse(Trusty.ToString());
                int Citationflow = Int32.Parse(City.ToString());
                int Reffering = Int32.Parse(RIPy.ToString());

                int[] Metrics = new int[] { Trustflow, Citationflow, Reffering };

                return Metrics;


You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.311664 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO