title: Curl vs CPPREST
body: <p>I am trying to access an URL, using CPPREST http_client : </p>
  
  <p><a href="http://www.20min.ch/rss/rss.tmpl?type=channel&amp;get=68" rel="nofollow">http://www.20min.ch/rss/rss.tmpl?type=channel&amp;get=68</a></p>
  
  <p>I am receiving response code 302 for URL- redirection.</p>
  
  <p>But when i try to access the same URL using CURL, I am receiving CURLE_OK.</p>
  
  <p>Below are the 2 piece of code : </p>
  
  <blockquote>
    <p>using CURL :</p>
  </blockquote>
  
  <pre><code>CURL *curl;
  CURLcode res;
  curl_global_init(CURL_GLOBAL_ALL);
  curl = curl_easy_init();
  if(curl){
      curl_easy_setopt(curl, CURLOPT_URL, "http://www.20min.ch/rss/rss.tmpl?type=channel&amp;get=68");
      res = curl_easy_perform(curl);
      if(res != CURLE_OK)     {
          cout&lt;&lt;"failed";
      }
      else  {
          cout&lt;&lt;"success";
      }
      curl_easy_cleanup(curl);
  }
  curl_global_cleanup();
  </code></pre>
  
  <p>The output is : success</p>
  
  <blockquote>
    <p>using CPPREST :</p>
  </blockquote>
  
  <pre><code>std::string url_= "http://www.20min.ch/rss/rss.tmpl?type=channel&amp;get=68";
  try
  {
       http_client client1(U(url_));
       uri_builder builder1(U(""));
       client1.request(methods::GET, builder1.to_string()).then([=](http_response response)
       {
          cout&lt;&lt;"Response code is : "&lt;&lt;response.status_code();
       });
  }
  catch(std::exception&amp; e)
  {
      cout&lt;&lt;"response :"&lt;&lt;e.what();
  }
  </code></pre>
  
  <p>The output is :: Response code is : 302</p>
  
  <p>I do not understand why the two libs are behaving differently for same URL??</p>
  
  <p><strong>UPDATE :</strong></p>
  
  <p>I have also tried with : </p>
  
  <pre><code>http_client client1(utility::conversions::to_string_t(url_));
  </code></pre>
  
  <p>and</p>
  
  <pre><code>http_client client1(U("http://www.20min.ch/rss/rss.tmpl?type=channel&amp;get=68"));
  </code></pre>
  
  <p>and </p>
  
  <pre><code>http_client client1(U("http://www.20min.ch/"));
  </code></pre>
  
  <p>but the response is same 302 with cpp rest. [ for cross checking <a href="http://casablanca.codeplex.com/wikipage?title=Http%20Client%20Tutorial" rel="nofollow">bing example</a></p>
  
  <p>is working fine]</p>
  
  <p><strong>UPDATE 2:</strong></p>
  
  <p>The method as explained by @Matt Weber seems very helpful and legit but i am continuously getting error code : 400 for that, So I tried the below things:
  I tried to set the host and port for the URL in uri_builder.</p>
  
  <pre><code>http_client client(U("http://www.20min.ch/rss/"));
  uri_builder builder(U("/rss.tmpl"));
  builder.append_query(U("type"), U("channel"));
  builder.append_query(U("get"), U("68"));
  builder.set_host(U("www.20min.ch"));
  builder.set_port(U("80"));
  client.request(methods::GET, builder.to_string()).then([=](http_response response)
  {
       cout&lt;&lt;"Received response status code: "&lt;&lt;response.status_code();
  });
  </code></pre>
  
  <p>but still same 302.</p>