I am trying to deserialize a json request but getting error that
Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at input location [2,2]
please do help me out with this error. my code :
public class connectionStoS_ctrl {
String clientId = 'jhjhjkjkjh.kjkkjkjjujbhokkoio79088kjkjmm';
String clientSecret = '56657767';
String username= '[email protected]';
String password= 'pasword';
String reqbody = 'grant_type=password&client_id='+clientId+'&client_secret='+clientSecret+'&username='+username+'&password='+password;
public connectionStoS_ctrl(){
requestToStoS();
}
public void requestToStoS(){
//OAuth2 oA1 = new OAuth2 (12, 'test1');
//OAuth2 oA2 = new OAuth2 (13, 'test2');
List<OAuth2> oALst= new List<OAuth2>();
//oALst.add(oA1);
//oALst.add(oA2);
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setBody(reqbody);
req.setMethod('GET');
req.setEndpoint('https://login.salesforce.com');//Note if my domain is set up use the proper domain name else use login.salesforce.com for prod or developer or test.salesforce.com for sandbox instance
System.debug('Http Request body '+ reqbody);
System.debug('Http Request '+ req);
HttpResponse res = h.send(req);
System.debug('obj Authentication Http Response '+ res.getbody() );
//string serialz = JSON.serialize(res.getbody());
//serialz = '{' + serialz ;
//System.debug('obj Authentication Http Response '+ res.getbody());
OAuth2 objAuthenticationInfo = (OAuth2) JSON.deserialize(String.valueof(res.getbody()), OAuth2.class);
System.debug('obj Authentication Info 1 '+ JSON.deserialize(res.getbody(), OAuth2.class));
System.debug('obj Authentication Info 2 '+objAuthenticationInfo.oauth_token);
//if(objAuthenticationInfo.access_token != null){
//System.debug(' Inside oAuth ');
Http h1 = new Http();
HttpRequest req1 = new HttpRequest();
//req1.setHeader('Authorization','Bearer '+objAuthenticationInfo);
req1.setHeader('Content-Type','application/json');
req1.setHeader('accept','application/json');
System.debug('jsonstr_BODY '+req1);
//req1.setBody(jsonstr);//Send JSON body
//req1.setMethod('POST');
//req1.setEndpoint(https://login.salesforce.com/services/oauth2/callback+URL);//URL will be your Salesforce REST API end point where you will do POST,PUT,DELETE orGET
//HttpResponse res1 = h1.send(req1);
//system.debug('RESPONSE_BODY'+res1.getbody());
//}
}
public class OAuth2{
public String oauth_callback{get;set;}
//public String issued_at{get;set;}
//public String instance_url{get;set;}
//public String signature{get;set;}
public String oauth_token{get;set;}
}
}
response body
<html>
<head></head><body onload="document.forms['workerForm'].submit()">
<form action="https://ap1.salesforce.com/visualforce/session" id="workerForm" method="post" name="workerForm" >
<input type="hidden" name="client_id" id="client_id" value="rCVPxkDShqbjaG_G1fAV" />
<input type="hidden" name="client_secret" id="client_secret" value="hgj87687nb" />
<input type="hidden" name="grant_type" id="grant_type" value="password" />
<input type="hidden" name="password" id="password" value="kjhd7824fdjds" />
<input type="hidden" name="url" id="url" value="https://streamingapi.ap1.visual.force.com/apex/streamingapi__ConnectionStoS_Received" />
<input type="hidden" name="username" id="username" value="[email protected]" />
</form>
Please guide me what i am doing wrong.