+ Start a Discussion
Akshita SinghAkshita Singh 

How to make a Post method request to send

 { "requested_phoneNumber": "u7uMifPUDkJfWaNOmPbxSHZmN35Yaz7pjMo==", "otp": "12345" }
 
Kancharla ChakravarthyKancharla Chakravarthy
Use the below code and test from Postman or Work bench or Dev console
 
JSONGenerator gen = JSON.createGenerator(true);    
	gen.writeStartObject();      
	gen.writeStringField('requested_phoneNumber', 'u7uMifPUDkJfWaNOmPbxSHZmN35Yaz7pjMo==');
	gen.writeStringField('otp','12345');
	gen.writeEndObject();    
	String jsonS = gen.getAsString();
	System.debug('jsonMaterials'+jsonS);

	// Sening the http body with JSON 

	String endpoint = 'http://www.example.com/service';
	HttpRequest req = new HttpRequest();
	req.setEndpoint(endpoint);
	req.setMethod('POST');
	req.setbody(jsonS);
	Http http = new Http();
	HTTPResponse response = http.send(req);

Please choose as best answer if the above code works for you. It will help others to find the best answers