title: getting BAD REQUEST error for simple GET method REST API using Poco::Net::HTTPClientSession in C++
body: <p>RESTful Service is available and it is giving correct response using curl GET Method. It has basic Authentication mechanism. Below is command and output.</p>
  <p><strong>curl --header &quot;Authorization: Basic YWw6NG01RzZsOG41UDlpMXAzTjZzOGQ=&quot;  'http://localhost:8153/api.rsc/FBI_dbo_PERSON(per_id=10001)'</strong></p>
  <p><em>{&quot;@odata.context&quot;:&quot;http://localhost:8153/api.rsc/$metadata#FBI_dbo_PERSON/$entity&quot;, &quot;ALERTLEVEL&quot;: &quot;3 &quot;, &quot;DATEENTERED&quot;: &quot;1966-09-12T00:00:00.0000+05:30&quot;, &quot;PER_CITIZENOF&quot;: &quot;SDASDAS&quot;, &quot;PER_DOB&quot;: &quot;1944-06-11T00:00:00.0000+05:30&quot;, &quot;PER_FamilyName&quot;: &quot;GHGH&quot;, &quot;PER_FirstName&quot;: &quot;UIUY&quot;, &quot;PER_ID&quot;: &quot;10001&quot;, &quot;PER_PASSPORTNUM&quot;: &quot;4564TRT2342&quot;, &quot;TBROWID&quot;: 9001}</em></p>
  <p>Now for same GET request and authentication, I am using C++ Poco library, it am getting BAD REQUEST error. Not sure why, I tried  changes at my end where I could, but still same error. I think Authorization is happening correctly here.
  Below is the sample code for the same. Any idea how to resolve this.</p>
  <pre><code>int main(){
  
  std::string sRet;
  std::string sURL= &quot;http://localhost:8153/api.rsc/FBI_dbo_PERSON(per_id=10001)&quot;;
  std::string m_sAuthorization = &quot;Basic YWw6NG01RzZsOG41UDlpMXAzTjZzOGQ=&quot;;
  std::string sRESTMethod = &quot;GET&quot;;
  
  try
  {
          Poco::URI uri(sURL);
          Poco::Net::HTTPClientSession session(uri.getHost(), uri.getPort());      
          Poco::Net::HTTPRequest request;         
          request.setURI(sURL);
          session.setKeepAlive(true);
          request.setKeepAlive(true);         
          request.add(&quot;Authorization&quot;, m_sAuthorization);
          printf(&quot;Making HTTPRequest for &lt;%s&gt; \n&quot;, sURL.c_str());
          if(sRESTMethod.compare(&quot;GET&quot;)==0)
          {
              try
              {
                  request.setMethod(Poco::Net::HTTPRequest::HTTP_GET);                                
                  session.sendRequest(request);
              }
              catch(Poco::Exception &amp;ex)
              {
                  printf(&quot;Exception trying to send request&lt;%s&gt;. \n&quot;, sURL.c_str());
                  printf(&quot;Exception message&lt;%s&gt; \n&quot;, ex.message().c_str());
              }
          }
  
          Poco::Net::HTTPResponse response;
          std::istream&amp; rs = session.receiveResponse(response);
          std::string sResponseReason = std::string(response.getReason());
          std::ostringstream oss;
          Poco::StreamCopier::copyStream(rs, oss);            
          sRet = oss.str();
          std::cout &lt;&lt; &quot;Response Status : &quot; &lt;&lt; response.getStatus() &lt;&lt; std::endl;
          if(sResponseReason.compare(&quot;OK&quot;)==0)
          {
              printf(&quot;HTTPReponse OK :::  %s for &lt;%s&gt; \n&quot;, sResponseReason.c_str(), sURL.c_str());
              if(!sRequestContent.empty())
                  printf(&quot;Request Content is &lt;%s&gt; \n&quot;, sRequestContent.c_str());
          }
          else
          {
              printf(&quot;HTTPReponse NOT OK ::  %s:&lt;%s&gt; for &lt;%s&gt; \n&quot;, sResponseReason.c_str(), sRet.c_str(), sURL.c_str());
              sRet = &quot;&quot;;
          }
  }
  catch (Poco::Exception &amp;ex)
  {        
      printf(&quot;Exception&lt;%s&gt; \n&quot;, ex.displayText().c_str());
      sRet = &quot;&quot;;
  }
  std::cout &lt;&lt;  sRet &lt;&lt; std::endl;
  return 0;
  </code></pre>
  <p>}</p>
  <p>This is the output if I run the binary :</p>
  <p><strong>Making HTTPRequest for <a href="http://localhost:8153/api.rsc/FBI_dbo_PERSON(per_id=10001)" rel="nofollow noreferrer">http://localhost:8153/api.rsc/FBI_dbo_PERSON(per_id=10001)</a>
  Response Status : 400
  HTTPReponse NOT OK ::  Bad Request:&lt;Bad Request&gt; for <a href="http://localhost:8153/api.rsc/FBI_dbo_PERSON(per_id=10001)" rel="nofollow noreferrer">http://localhost:8153/api.rsc/FBI_dbo_PERSON(per_id=10001)</a></strong></p>