title: Looping or iterating through a secure web request to retrieve all records from ESRI Feature Service using C#
body: <p>I am relatively new to C#. I am working on a C# console application to sync data from GIS to a business system. The datasets I am retrieving from GIS are larger than the allowed record set returned from querying the service. Below is my code for retrieving data from the service (URL modified for public display). Is there a way I can loop or iterate through the request to pull all records for the dataset? The code below works to retrieve the first 2000 records of the dataset.</p>
  <p>public static string MyData
  {</p>
  <pre><code>        get
          {
              var token = GetToken();
              string result = string.Empty;
              var url = new Uri(&quot;https://mydata.com/mapping/rest/services/GeoEvent/MyData/FeatureServer/0/query?where=0%3D0&amp;text=&amp;objectIds=&amp;time=&amp;geometry=&amp;geometryType=esriGeometryEnvelope&amp;inSR=&amp;spatialRel=esriSpatialRelIntersects&amp;relationParam=&amp;outFields=OBJECTID,SIID,COLL_METHOD,COLL_STATUS,COLL_CMTS,CREATED_BY,CREATED_DATE,MODIFIED_BY,MODIFIED_DATE,SID&amp;returnGeometry=true&amp;returnTrueCurves=false&amp;maxAllowableOffset=&amp;geometryPrecision=&amp;outSR=4269&amp;having=&amp;returnIdsOnly=false&amp;returnCountOnly=false&amp;orderByFields=OBJECTID&amp;groupByFieldsForStatistics=&amp;outStatistics=&amp;returnZ=false&amp;returnM=false&amp;gdbVersion=&amp;historicMoment=&amp;returnDistinctValues=false&amp;resultOffset=&amp;resultRecordCount=&amp;queryByDistance=&amp;returnExtentOnly=false&amp;datumTransformation=&amp;parameterValues=&amp;rangeValues=&amp;quantizationParameters=&amp;featureEncoding=esriDefault&amp;f=pjson&quot;);
              var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
              httpWebRequest.Host = &quot;mydata.com&quot;;
              httpWebRequest.Headers.Add(&quot;X-Esri-Authorization&quot;, &quot;Bearer &quot; + token);
              httpWebRequest.Method = &quot;GET&quot;;
              var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
              using (StreamReader streamReader = new StreamReader(httpResponse.GetResponseStream()))
              {
                  result = streamReader.ReadToEnd();
              }
  
                           
              Rootobject obj = JsonConvert.DeserializeObject&lt;Rootobject&gt;(result);
               foreach(Feature featureitem in obj.features)
              {
                  Console.WriteLine(featureitem.attributes.OBJECTID + &quot;-&quot; + featureitem.attributes.COLL_STATUS + &quot;-&quot; + featureitem.attributes.CREATED_BY + &quot;-&quot; + featureitem.attributes.CREATED_DATE + &quot;-&quot; + featureitem.attributes.MODIFIED_BY + &quot;-&quot; + featureitem.attributes.COLL_CMTS + &quot;-&quot; + featureitem.attributes.SID + &quot;-&quot; + featureitem.attributes.SIID + &quot;-&quot; + featureitem.geometry.x + &quot;-&quot; + featureitem.geometry.y);
              }
  </code></pre>