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

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();
          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');
          String strResp ;
              HTTPResponse resp1 = h.send(r);
              strResp = resp1.toString();
              ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.INFO,strResp);
              return strResp;

          }catch (Exception e)

>curl -i -k -u <User>:<pwd> -H "If-Modified-Since: Thu, 05 Jul 2012 15:31:30 GMT" > gitgub3.txt

Also, r.setEndpoint('<username>/testing'); send data with CURL and send response OK with code

Any suggestion???

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