function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
gaurav.sfdcgaurav.sfdc 

Intergration with GitHub Api using basic authentication

I am trying to connect with Git Hub via http,  it gets connected [respone 200] then when I try to get data it just returns [response 200 OK] but return no data. However when I am using by curl it returm complete Json data. Why it is not working with http request: Please find code below

         HTTP h = new HTTP();
          HTTPRequest r = new HTTPRequest();
          r.setEndpoint('https://api.github.com/user');
          Blob headerValue = Blob.valueOf(sUsername + ':' + sPassword);
          String authorizationHeader = 'Basic ' + EncodingUtil.base64Encode(headerValue);
          r.setHeader('Authorization', authorizationHeader);
          r.setHeader('If-Modified-Since', 'Thu, 05 Jul 2012 15:31:30 GMT');
          r.setHeader('Accept', 'application/json');
          r.setHeader('Content-Type', 'application/json');
          r.setMethod('GET');
          String strResp ;
          try
          {
              HTTPResponse resp1 = h.send(r);
              strResp = resp1.toString();
              ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.INFO,strResp);
              ApexPages.addMessage(myMsg);
              return strResp;

          }catch (Exception e)
          {}

With CURL
>curl -i -k -u <User>:<pwd> https://api.github.com/user -H "If-Modified-Since: Thu, 05 Jul 2012 15:31:30 GMT" > gitgub3.txt

Also, r.setEndpoint('https://api.github.com/repos/<username>/testing'); send data with CURL and send response OK with code

Any suggestion???

Best Answer chosen by gaurav.sfdc
gaurav.sfdcgaurav.sfdc
One small thig is missing, It should be resp1.getBody(); however this resolved my own question.