You need to sign in to do that
Don't have an account?

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???
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???


One small thig is missing, It should be resp1.getBody(); however this resolved my own question.