Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

SAP ABAP HTTP Request Post Method using a REST API Call

burakozcetinn62
Discoverer
0 Kudos
5,666

Hi Expers,

Our company wants to integrate with a non-SAP product. We've done the GET methods, but we're having trouble with the POST methods. We need to send json data via rest api.The example code shared with us is as follows. I want to transform this code blocks to ABAP language.

static void Upload(String url, String path_locator,
String subfolder, String file, String token)
 {
 string requestUrl = string.Format("{0}/RestServices/UploadFile/{1}/{2}/{3}", 
url, 
Base64Encode(path_locator), 
Base64Encode(subfolder), 
Base64Encode(System.IO.Path.GetFileName(file)), 
token);
 HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(requestUrl);
 request.Method = "POST";
 request.ContentType = "application/octet-stream";
 // txtFileName contains the name of the file to upload.
 byte[] fileToSend = File.ReadAllBytes(file); 
 request.ContentLength = fileToSend.Length;
 using (Stream requestStream = request.GetRequestStream())
 {
 // Send the file as body request. 
 requestStream.Write(fileToSend, 0, fileToSend.Length);
 requestStream.Close();
 }
 using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
 Console.WriteLine("HTTP/{0} {1} {2}", 
response.ProtocolVersion, 
(int)response.StatusCode, 
response.StatusDescription);
 }

Thank you all.

4 REPLIES 4

Sandra_Rossi
Active Contributor
0 Kudos
3,693

Your code is just about doing an HTTP call and encoding using base64, and probably UTF-8 as it sends "octets". I see nothing very specific about JSON.

Concerning HTTP call, base64 and UTF-8, you can find lots of questions and answers in the forum. Search "CL_HTTP_CLIENT", "Base64" and "CL_ABAP_CODEPAGE".

If you have questions about JSON, you can also find many questions and answers in the forum.


0 Kudos
3,693

Yes other parameters will send via url. But how can I send JSON Data?

0 Kudos
3,693

Could you clarify your question about sending JSON? There could be 12400 different answers.

OlegBash
Active Participant